Skip to content

Commit 110486d

Browse files
committed
feat: Console.logLevel
Update arguments-builder.config.ts Update Microsoft.Translate.dev.js Update Microsoft.Translate.js Update boxjs.settings.json Update database.mjs Update setENV.mjs Update types.d.ts
1 parent 659fef3 commit 110486d

File tree

9 files changed

+293
-270
lines changed

9 files changed

+293
-270
lines changed

arguments-builder.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,20 @@ export default defineConfig({
3232
},
3333
},
3434
args: [
35+
{
36+
key: "LogLevel",
37+
name: "[调试] 日志等级",
38+
type: "string",
39+
defaultValue: "WARN",
40+
description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。",
41+
options: [
42+
{ key: "OFF", label: "关闭" },
43+
{ key: "ERROR", label: "❌ 错误" },
44+
{ key: "WARN", label: "⚠️ 警告" },
45+
{ key: "INFO", label: "ℹ️ 信息" },
46+
{ key: "DEBUG", label: "🅱️ 调试" },
47+
{ key: "ALL", label: "全部" },
48+
],
49+
},
3550
],
3651
});

package-lock.json

Lines changed: 232 additions & 238 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
"node-polyfill-webpack-plugin": "^4.0.0"
4444
},
4545
"dependencies": {
46-
"@nsnanocat/util": "^1.7.5"
46+
"@nsnanocat/util": "^1.7.6"
4747
}
4848
}

src/Microsoft.Translate.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const $request = {
88
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
99
},
1010
};
11-
Console.logLevel = "DEBUG";
1211
/***************** Processing *****************/
1312
(async () => {
1413
/**
1514
* 设置
1615
* @type {{Settings: import('./types').Settings}}
1716
*/
1817
const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database);
18+
Console.logLevel = Settings.LogLevel;
1919
const $response = await fetch($request);
2020
_.set(Settings, "Vendor", "Microsoft");
2121
_.set(Settings, "Microsoft.Version", "Azure");

src/Microsoft.Translate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const $request = {
1515
* @type {{Settings: import('./types').Settings}}
1616
*/
1717
const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database);
18+
Console.logLevel = Settings.LogLevel;
1819
const $response = await fetch($request);
1920
_.set(Settings, "Vendor", "Microsoft");
2021
_.set(Settings, "Microsoft.Version", "Azure");

src/function/database.mjs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
export default {
2-
"Default": {
3-
"Settings": {
4-
"Type": "Translate",
5-
"Types": [
6-
"Official",
7-
"Translate"
8-
],
9-
"Languages": [
10-
"EN",
11-
"ZH"
12-
],
13-
"CacheSize": 50
14-
},
15-
"Configs":{
16-
"breakLine":{
17-
"text/xml":"
",
18-
"application/xml":"
",
19-
"text/vtt":"\n",
20-
"application/vtt":"\n",
21-
"text/json":"\n",
22-
"application/json":"\n"
23-
}
24-
}
25-
}
26-
}
2+
Default: {
3+
Settings: {
4+
Type: "Translate",
5+
Types: ["Official", "Translate"],
6+
Languages: ["EN", "ZH"],
7+
CacheSize: 50,
8+
LogLevel: "WARN",
9+
},
10+
Configs: {
11+
breakLine: {
12+
"text/xml": "
",
13+
"application/xml": "
",
14+
"text/vtt": "\n",
15+
"application/vtt": "\n",
16+
"text/json": "\n",
17+
"application/json": "\n",
18+
},
19+
},
20+
},
21+
};

src/function/setENV.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ export default function setENV(name, platforms, database) {
1212
Console.log("☑️ Set Environment Variables");
1313
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
1414
/***************** Settings *****************/
15-
if (!Array.isArray(Settings?.Types)) Settings.Types = (Settings.Types) ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔
16-
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`);
15+
if (!Array.isArray(Settings?.Types)) Settings.Types = Settings.Types ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔
16+
Console.info(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`);
1717
/***************** Caches *****************/
18-
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
1918
if (typeof Caches?.Playlists !== "object" || Array.isArray(Caches?.Playlists)) Caches.Playlists = {}; // 创建Playlists缓存
2019
Caches.Playlists.Master = new Map(JSON.parse(Caches?.Playlists?.Master || "[]")); // Strings转Array转Map
2120
Caches.Playlists.Subtitle = new Map(JSON.parse(Caches?.Playlists?.Subtitle || "[]")); // Strings转Array转Map
2221
if (typeof Caches?.Subtitles !== "object") Caches.Subtitles = new Map(JSON.parse(Caches?.Subtitles || "[]")); // Strings转Array转Map
2322
if (typeof Caches?.Metadatas !== "object" || Array.isArray(Caches?.Metadatas)) Caches.Metadatas = {}; // 创建Playlists缓存
2423
if (typeof Caches?.Metadatas?.Tracks !== "object") Caches.Metadatas.Tracks = new Map(JSON.parse(Caches?.Metadatas?.Tracks || "[]")); // Strings转Array转Map
24+
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
2525
/***************** Configs *****************/
2626
Console.log("✅ Set Environment Variables");
2727
return { Settings, Caches, Configs };
28-
};
28+
}

src/types.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
export interface Settings {
2+
/**
3+
* [调试] 日志等级
4+
*
5+
* 选择脚本日志的输出等级,低于所选等级的日志将全部输出。
6+
*
7+
* @remarks
8+
*
9+
* Possible values:
10+
* - `'OFF'` - 关闭
11+
* - `'ERROR'` - ❌ 错误
12+
* - `'WARN'` - ⚠️ 警告
13+
* - `'INFO'` - ℹ️ 信息
14+
* - `'DEBUG'` - 🅱️ 调试
15+
* - `'ALL'` - 全部
16+
*
17+
* @defaultValue "WARN"
18+
*/
19+
LogLevel?: 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'ALL';
220
}

template/boxjs.settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[]
1+
[{"id":"@DualSubs.AddOn.Settings.LogLevel","name":"[调试] 日志等级","type":"selects","val":"WARN","items":[{"key":"OFF","label":"关闭"},{"key":"ERROR","label":"❌ 错误"},{"key":"WARN","label":"⚠️ 警告"},{"key":"INFO","label":"ℹ️ 信息"},{"key":"DEBUG","label":"🅱️ 调试"},{"key":"ALL","label":"全部"}],"desc":"选择脚本日志的输出等级,低于所选等级的日志将全部输出。"}]

0 commit comments

Comments
 (0)