what-is-surprise
Version:
translate tool
79 lines (78 loc) • 2.96 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "md5", "../../utils"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaiduFanyiReqConfig = void 0;
var md5_1 = __importDefault(require("md5"));
var utils_1 = require("../../utils");
var BaiduFanyiReqConfig = /** @class */ (function () {
function BaiduFanyiReqConfig(config) {
this.q = '';
this.appid = '';
this.salt = Date.now().toString();
this.from = 'auto';
this.to = 'auto';
this.sign = '';
this.key = '';
Object.assign(this, config);
}
BaiduFanyiReqConfig.prototype.updateQuery = function (query) {
if (query === void 0) { query = ''; }
this.q = query;
return this;
};
BaiduFanyiReqConfig.prototype.updateAppId = function (appId) {
if (appId === void 0) { appId = ''; }
this.appid = appId;
return this;
};
BaiduFanyiReqConfig.prototype.updateSalt = function (salt) {
if (salt === void 0) { salt = ''; }
this.salt = salt;
return this;
};
BaiduFanyiReqConfig.prototype.updateFrom = function (from) {
if (from === void 0) { from = 'auto'; }
this.from = from;
return this;
};
BaiduFanyiReqConfig.prototype.updateTo = function (to) {
if (to === void 0) { to = 'auto'; }
this.to = to;
return this;
};
/**
* 根据当前配置信息更新签名 sign 的值
* @param sign 已确定的签名值,可选,推荐不传
*/
BaiduFanyiReqConfig.prototype.updateSign = function (sign) {
if (sign === void 0) { sign = ''; }
if (typeof sign === 'string' && sign) {
this.sign = sign;
}
else {
var _a = this, appid = _a.appid, q = _a.q, salt = _a.salt, key = _a.key;
this.sign = md5_1.default(appid + q + salt + key);
}
return this;
};
/**
* 创建当前配置冻结副本
*/
BaiduFanyiReqConfig.prototype.release = function () {
return Object.freeze(utils_1.pick(this, ['q', 'appid', 'salt', 'from', 'to', 'sign', 'key']));
};
return BaiduFanyiReqConfig;
}());
exports.BaiduFanyiReqConfig = BaiduFanyiReqConfig;
});