doomi-helper
Version:
Doomisoft NodeJs Common Utilities
124 lines (118 loc) • 5.13 kB
JavaScript
// var querystring = require("querystring")
// var crypto = require('crypto');
// var path = require('path');
// var fs = require('fs');var jwt = require('jwt-simple')
// const tencentcloud = require("tencentcloud-sdk-nodejs");
// const VodClient = tencentcloud.vod.v20180717.Client;
// const models = tencentcloud.vod.v20180717.Models;
// const Credential = tencentcloud.common.Credential;
// const ClientProfile = tencentcloud.common.ClientProfile;
// const HttpProfile = tencentcloud.common.HttpProfile;
// //const secret_id = config.tencentApi.SecretId;
// //const secret_key = config.tencentApi.SecretKey;
// // const APPID = 1303174727; //GAMA 学习的appid
// // const SIGNKEY = 'GAMADoomisoft';
// //const PLAYERNAME = 'GAMAPLAYER';
// //const BASE_VIDEO_URL = 'http://1303174727.vod2.myqcloud.com'
// class VodUtility {
// constructor(secret_id,secret_key){
// this.secret_id = secret_id;
// this.secret_key = secret_key;
// }
// /**
// * 当前配置中的腾讯云短信实例配置
// */
// static getInstance(){
// if (!VodUtility.instance) {
// let configfilename = process.env.CONFIGFILE || 'configuration.json';
// let configfile = path.join(process.cwd(), configfilename);
// if (!fs.existsSync(configfile)) throw new Error('Missing app configuration file')
// let config = require(configfile);
// VodUtility.instance = new VodUtility(config.tencentApi.SecretId,config.tencentApi.SecretKey);
// }
// return VodUtility.instance;
// }
// getSignature() {
// // 确定签名的当前时间和失效时间
// var current = parseInt((new Date()).getTime() / 1000)
// var expired = current + 86400; // 签名有效期:1天
// // 向参数列表填入参数
// var arg_list = {
// secretId: this.secret_id,
// currentTimeStamp: current,
// expireTime: expired,
// random: Math.round(Math.random() * Math.pow(2, 32))
// }
// // 计算签名
// var orignal = querystring.stringify(arg_list);
// var orignal_buffer = Buffer.from(orignal, "utf-8"); // new Buffer(orignal, "utf8");
// var hmac = crypto.createHmac("sha1", this.secret_key);
// var hmac_buffer = hmac.update(orignal_buffer).digest();
// var signature = Buffer.concat([hmac_buffer, orignal_buffer]).toString("base64");
// // 确定 app 的云 API 密钥
// return signature;
// }
// /**
// * 超级播放器签名
// */
// getPlayerSign(fileid, limit,APPID,SIGNKEY,PLAYERNAME) {
// // 确定签名的当前时间和失效时间
// var payload = {
// appId: APPID,
// fileId: fileid,
// currentTimeStamp: Math.floor(Date.now() / 1000),
// expireTimeStamp: Math.floor(Date.now() / 1000) + 86400,
// pcfg: PLAYERNAME,
// urlAccessInfo: {
// t: (Math.floor(Date.now() / 1000) + 86400).toString(16).toUpperCase()
// }
// }
// if (limit && limit >= 30) {
// payload.urlAccessInfo.exper = limit;
// }
// let token = jwt.encode(payload, SIGNKEY);
// return token;
// }
// /**
// * 获取原始链接的播放签名
// */
// getUrlSign(fileUrl,SIGNKEY,BASE_VIDEO_URL, limit = 3600) {
// // 确定签名的当前时间和失效时间
// let dirName = fileUrl.replace(BASE_VIDEO_URL, '').split('/');
// let t = (Math.floor(Date.now() / 1000) + limit).toString(16);
// dirName[dirName.length - 1] = '';
// let path = dirName.join('/')
// // console.log('source',SIGNKEY+path+t.toString(16))
// let sign = crypto.createHash("md5")
// .update(SIGNKEY + path + t.toString(16))
// .digest('hex');
// return `t=${t}&sign=${sign}`
// }
// /**
// * 视频处理,用预设的模板进行转
// * Definition":20
// * MP4-标清-SD MP4 640 x 360
// */
// processByProcedure(FileId, procedureName = 'GAMA-TASK') {
// let cred = new Credential(this.secret_id, this.secret_key);
// let httpProfile = new HttpProfile();
// httpProfile.endpoint = "vod.tencentcloudapi.com";
// let clientProfile = new ClientProfile();
// clientProfile.httpProfile = httpProfile;
// let client = new VodClient(cred, "ap-chongqing", clientProfile);
// let req = new models.ProcessMediaByProcedureRequest();
// let params = {
// "FileId": FileId,
// "ProcedureName": procedureName
// };
// req.from_json_string(JSON.stringify(params));
// client.ProcessMediaByProcedure(req, function (errMsg, response) {
// if (errMsg) {
// console.log(errMsg);
// return;
// }
// console.log(response.to_json_string());
// });
// }
// }
// exports = module.exports = VodUtility;