tencentcloud-edgeone-migration-nodejs-v2
Version:
tencentcloud cdn config copy to edgeone
90 lines (80 loc) • 1.99 kB
JavaScript
const tencentcloud = require("tencentcloud-sdk-nodejs");
const { lang } = require("../i18n/trans");
const CdnClient = tencentcloud.cdn.v20180606.Client;
const EoClient = tencentcloud.teo.v20220901.Client;
const SslClient = tencentcloud.ssl.v20191205.Client;
const langMap = {
zh: "zh-CN",
en: "en-US",
};
const language = langMap[lang];
const { SecretId, SecretKey } = require("../config.json");
const genLog = require("../logGenerator");
const API = function (secretId, secretKey) {
const cdnClient = new CdnClient({
credential: {
secretId: secretId,
secretKey: secretKey,
},
// 产品地域
region: "ap-guangzhou",
// 可选配置实例
profile: {
language,
signMethod: "TC3-HMAC-SHA256",
httpProfile: {
reqMethod: "POST",
reqTimeout: 30,
},
},
});
const eoClient = new EoClient({
credential: {
secretId: secretId,
secretKey: secretKey,
},
// 产品地域
region: "ap-shanghai",
// 可选配置实例
profile: {
language,
signMethod: "TC3-HMAC-SHA256",
httpProfile: {
reqMethod: "POST",
reqTimeout: 30,
},
},
});
const sslClient = new SslClient({
credential: {
secretId: secretId,
secretKey: secretKey,
},
// 产品地域
region: "ap-shanghai",
// 可选配置实例
profile: {
language,
signMethod: "TC3-HMAC-SHA256",
httpProfile: {
reqMethod: "POST",
reqTimeout: 30,
},
},
});
this.cdnClient = cdnClient;
this.eoClient = eoClient;
this.sslClient = sslClient;
};
const capi = async (action, client, params) => {
try {
const request = new API(SecretId, SecretKey);
genLog.fetchLog(action, { payload: params });
const response = await request[client][action](params);
genLog.fetchLog(action, { response });
return response;
} catch (error) {
throw error;
}
};
module.exports = capi;