koishi-plugin-ets2-tools-tmp 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/command/ets-app/queryPoint.js +1 -1
- package/lib/command/ets-app/resetPassword.js +2 -2
- package/lib/command/tmpActivityService.js +603 -0
- package/lib/command/tmpQuery/tmpQuery.js +1 -1
- package/lib/command/tmpQuery/tmpQueryText.js +2 -5
- package/lib/command/tmpTraffic/tmpTraffic.js +1 -1
- package/lib/command/tmpTraffic/tmpTrafficMap.js +0 -4
- package/lib/command/tmpTraffic/tmpTrafficText.js +0 -2
- package/lib/index.js +163 -693
- package/lib/util/baiduTranslate.js +5 -5
- package/package.json +1 -1
|
@@ -3,11 +3,11 @@ const translateCache = require('../database/translateCache');
|
|
|
3
3
|
const TRANSLATE_API = 'https://fanyi-api.baidu.com/api/trans/vip/translate';
|
|
4
4
|
module.exports = async (ctx, cfg, content, cache = true) => {
|
|
5
5
|
// 没有开启百度翻译功能,直接返回文本
|
|
6
|
-
if (!cfg.
|
|
6
|
+
if (!cfg.baiduTranslate?.enable) {
|
|
7
7
|
return content;
|
|
8
8
|
}
|
|
9
9
|
// 如果开启了缓存,尝试从缓存中查询翻译
|
|
10
|
-
if (cfg.
|
|
10
|
+
if (cfg.baiduTranslate?.cacheEnable && cache) {
|
|
11
11
|
let translateContent = await translateCache.getTranslate(ctx.database, md5(content));
|
|
12
12
|
if (translateContent) {
|
|
13
13
|
return translateContent;
|
|
@@ -15,15 +15,15 @@ module.exports = async (ctx, cfg, content, cache = true) => {
|
|
|
15
15
|
}
|
|
16
16
|
// 创建请求秘钥
|
|
17
17
|
let randomInt = Math.floor(Math.random() * 10000);
|
|
18
|
-
let sign = md5(cfg.
|
|
18
|
+
let sign = md5(cfg.baiduTranslate?.appId + content + randomInt + cfg.baiduTranslate?.key);
|
|
19
19
|
// 调用请求
|
|
20
|
-
let result = await ctx.http.get(`${TRANSLATE_API}?q=${encodeURI(content)}&from=auto&to=zh&appid=${cfg.
|
|
20
|
+
let result = await ctx.http.get(`${TRANSLATE_API}?q=${encodeURI(content)}&from=auto&to=zh&appid=${cfg.baiduTranslate?.appId}&salt=${randomInt}&sign=${sign}`);
|
|
21
21
|
// 如果翻译失败,直接返回内容
|
|
22
22
|
if (result.error_code) {
|
|
23
23
|
return content;
|
|
24
24
|
}
|
|
25
25
|
// 如果开启了缓存,将翻译内容缓存到数据库
|
|
26
|
-
if (cfg.
|
|
26
|
+
if (cfg.baiduTranslate?.cacheEnable && cache) {
|
|
27
27
|
translateCache.save(ctx.database, md5(content), content, result.trans_result[0].dst);
|
|
28
28
|
}
|
|
29
29
|
return result.trans_result[0].dst;
|