feat: 调用腾讯vod api
This commit is contained in:
parent
1b4175c8d0
commit
d649a14244
3
apps/admin/src/api/index.ts
Normal file
3
apps/admin/src/api/index.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import axios from "axios";
|
||||
|
||||
export const getVod = () => axios.post("/api/vod", { offset: 0, limit: 5000 });
|
|
@ -11,6 +11,9 @@ import {
|
|||
Tooltip,
|
||||
Image,
|
||||
} from "antd";
|
||||
import { useEffect } from "react";
|
||||
import { getVod } from "../../../api";
|
||||
import { useMount } from "../../../hooks";
|
||||
const { Search } = Input;
|
||||
|
||||
const Library = () => {
|
||||
|
@ -60,6 +63,12 @@ const Library = () => {
|
|||
|
||||
const onSearch = (value: string) => console.log(value);
|
||||
|
||||
useMount(() => {
|
||||
getVod().then((res) => {
|
||||
console.log(res);
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Row>
|
||||
|
|
|
@ -7,5 +7,12 @@ export default defineConfig({
|
|||
plugins: [react(), tsconfigPaths()],
|
||||
server: {
|
||||
port: 5174,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://172.20.160.221:7001/api",
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
# 代码中使用 process.env.OSS_SECRET
|
||||
OSS_SECRET=12345
|
||||
|
||||
|
||||
SECRET_ID=AKID534tZ7OvYzb2KQMwLYaVEl5FBwUtQWbU
|
||||
SECRET_KEY=q9HD6lQimeLp9IH5h7NRJzUpNjwxmPq5
|
|
@ -22,7 +22,8 @@
|
|||
"typeorm": "~0.3.0",
|
||||
"mysql2": "3.0.1",
|
||||
"dotenv": "16.0.3",
|
||||
"jsonwebtoken": "9.0.0"
|
||||
"jsonwebtoken": "9.0.0",
|
||||
"tencentcloud-sdk-nodejs": "4.0.552"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@midwayjs/cli": "^2.0.0",
|
||||
|
|
|
@ -2,6 +2,8 @@ import { Inject, Controller, Post, Body } from '@midwayjs/core';
|
|||
import { Context } from '@midwayjs/koa';
|
||||
import { Validate } from '@midwayjs/validate';
|
||||
import { UserDTO } from '../dto/user.dto';
|
||||
import * as tencentcloud from 'tencentcloud-sdk-nodejs';
|
||||
import { VodSearchDTO } from '../dto/vod.dto';
|
||||
|
||||
@Controller('/api')
|
||||
export class APIController {
|
||||
|
@ -15,4 +17,32 @@ export class APIController {
|
|||
async getUser(@Body() user: UserDTO) {
|
||||
return { success: true, message: 'OK', data: user };
|
||||
}
|
||||
|
||||
/**
|
||||
* 腾讯媒资管理查询
|
||||
* API调用demo: https://console.cloud.tencent.com/api/explorer?Product=vod&Version=2018-07-17&Action=SearchMedia
|
||||
* 最大返回5000条数据
|
||||
*/
|
||||
@Post('/vod')
|
||||
async vod(@Body() param: VodSearchDTO) {
|
||||
const { offset: Offset = 0, limit: Limit = 5000 } = param;
|
||||
const VodClient = tencentcloud.vod.v20180717.Client;
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: process.env.SECRET_ID,
|
||||
secretKey: process.env.SECRET_KEY,
|
||||
},
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: 'vod.tencentcloudapi.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
const client = new VodClient(clientConfig);
|
||||
const params = { SubAppId: 1500018521, Offset, Limit };
|
||||
return await client.SearchMedia(params).then(
|
||||
data => data,
|
||||
err => this.ctx.logger.error(err)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
10
apps/server/src/dto/vod.dto.ts
Normal file
10
apps/server/src/dto/vod.dto.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
// src/dto/user.ts
|
||||
import { Rule, RuleType } from '@midwayjs/validate';
|
||||
|
||||
export class VodSearchDTO {
|
||||
@Rule(RuleType.number().required())
|
||||
offset: number;
|
||||
|
||||
@Rule(RuleType.number().required())
|
||||
limit: number;
|
||||
}
|
|
@ -47,7 +47,8 @@
|
|||
"postcss": "8.4.21",
|
||||
"rollup-plugin-babel": "4.4.0",
|
||||
"@babel/core": "7.21.0",
|
||||
"rollup-plugin-dts": "5.2.0"
|
||||
"rollup-plugin-dts": "5.2.0",
|
||||
"axios": "1.3.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"object-hash": "^3.0.0"
|
||||
|
|
983
pnpm-lock.yaml
983
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user