feat: 调用腾讯vod api

This commit is contained in:
mozzie 2023-03-06 21:56:04 +08:00
parent 1b4175c8d0
commit d649a14244
9 changed files with 554 additions and 500 deletions

View File

@ -0,0 +1,3 @@
import axios from "axios";
export const getVod = () => axios.post("/api/vod", { offset: 0, limit: 5000 });

View File

@ -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>

View File

@ -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/, ""),
},
},
},
});

View File

@ -1,2 +1,6 @@
# 代码中使用 process.env.OSS_SECRET
OSS_SECRET=12345
SECRET_ID=AKID534tZ7OvYzb2KQMwLYaVEl5FBwUtQWbU
SECRET_KEY=q9HD6lQimeLp9IH5h7NRJzUpNjwxmPq5

View File

@ -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",

View File

@ -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)
);
}
}

View 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;
}

View File

@ -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"

File diff suppressed because it is too large Load Diff