Skip to content

Commit

Permalink
feat: $app & Console
Browse files Browse the repository at this point in the history
Update Microsoft.Translate.dev.js
Update Microsoft.Translate.js
Update boxjs.settings.json
Update CHANGELOG.md
Update database.mjs
Update setENV.mjs
Update types.d.ts
  • Loading branch information
VirgilClyne committed Nov 30, 2024
1 parent c1d28fd commit 595cfe8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 86 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
### 🔄 Other Changes
* util 由 `submodule` 更改为 `package`
### 🛠️ Bug Fixes
* 修复 `$argument``$persistentStore` 载入顺序颠倒的问题
* 正确顺序为先读取 `$argument` 再读取 `$persistentStore (BoxJs)`
* 即,有相同键名时,`$persistentStore (BoxJs)` 的值会覆盖 `$argument` 的值

### 🔣 Dependencies
* 升级了 `@nsnanocat/util`
* `util``submodule` 更改为 `package`
* `$platform` 改为 `$app`
* 使用了全新的 `Console` polyfill
35 changes: 13 additions & 22 deletions src/Microsoft.Translate.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $platform, Lodash as _, URL, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util";
import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util";
import database from "./function/database.mjs";
import setENV from "./function/setENV.mjs";
const $request = {
Expand All @@ -15,26 +15,17 @@ const $request = {
* @type {{Settings: import('./types').Settings}}
*/
const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database);
log(`⚠ Settings.Switch: ${Settings?.Switch}`, "");
switch (Settings.Switch) {
case true:
default: {
const $response = await fetch($request);
_.set(Settings, "Vendor", "Microsoft");
_.set(Settings, "Microsoft.Version", "Azure");
_.set(Settings, "Microsoft.Mode", "Token");
_.set(Settings, "Microsoft.Token", $response?.body);
log(`⚠ Settings: ${JSON.stringify(Settings)}`, "");
// 写入缓存
Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token);
break;
}
case false:
break;
}
const $response = await fetch($request);
_.set(Settings, "Vendor", "Microsoft");
_.set(Settings, "Microsoft.Version", "Azure");
_.set(Settings, "Microsoft.Mode", "Token");
_.set(Settings, "Microsoft.Token", $response?.body);
lConsole.info(`Settings: ${JSON.stringify(Settings)}`);
// 写入缓存
Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token);
})()
.catch(e => logError(e))
.catch(e => Console.error(e))
.finally(() => done());
35 changes: 13 additions & 22 deletions src/Microsoft.Translate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $platform, Lodash as _, URL, Storage, fetch, notification, log, logError, wait, done, getScript, runScript } from "@nsnanocat/util";
import { $app, Console, done, fetch, Lodash as _, notification, Storage, wait } from "@nsnanocat/util";
import database from "./function/database.mjs";
import setENV from "./function/setENV.mjs";
const $request = {
Expand All @@ -15,26 +15,17 @@ const $request = {
* @type {{Settings: import('./types').Settings}}
*/
const { Settings, Caches, Configs } = setENV("DualSubs", ["Translate", "API"], database);
log(`⚠ Settings.Switch: ${Settings?.Switch}`, "");
switch (Settings.Switch) {
case true:
default: {
const $response = await fetch($request);
_.set(Settings, "Vendor", "Microsoft");
_.set(Settings, "Microsoft.Version", "Azure");
_.set(Settings, "Microsoft.Mode", "Token");
_.set(Settings, "Microsoft.Token", $response?.body);
log(`⚠ Settings: ${JSON.stringify(Settings)}`, "");
// 写入缓存
Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token);
break;
}
case false:
break;
}
const $response = await fetch($request);
_.set(Settings, "Vendor", "Microsoft");
_.set(Settings, "Microsoft.Version", "Azure");
_.set(Settings, "Microsoft.Mode", "Token");
_.set(Settings, "Microsoft.Token", $response?.body);
Console.info(`Settings: ${JSON.stringify(Settings)}`);
// 写入缓存
Storage.setItem("@DualSubs.Translate.Settings.Vendor", Settings.Vendor);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Version", Settings.Microsoft.Version);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Mode", Settings.Microsoft.Mode);
Storage.setItem("@DualSubs.API.Settings.Microsoft.Token", Settings.Microsoft.Token);
})()
.catch(e => logError(e))
.catch(e => Console.error(e))
.finally(() => done());
1 change: 0 additions & 1 deletion src/function/database.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export default {
"Default": {
"Settings": {
"Switch": true,
"Type": "Translate",
"Types": [
"Official",
Expand Down
11 changes: 7 additions & 4 deletions src/function/setENV.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lodash as _, getStorage, log } from "@nsnanocat/util";
import { Console, getStorage, Lodash as _ } from "@nsnanocat/util";

/**
* Set Environment Variables
Expand All @@ -9,17 +9,20 @@ import { Lodash as _, getStorage, log } from "@nsnanocat/util";
* @return {Object} { Settings, Caches, Configs }
*/
export default function setENV(name, platforms, database) {
log("☑️ Set Environment Variables", "");
Console.log("☑️ Set Environment Variables");
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
/***************** Settings *****************/
if (!Array.isArray(Settings?.Types)) Settings.Types = (Settings.Types) ? [Settings.Types] : []; // 只有一个选项时,无逗号分隔
log(`✅ Set Environment Variables, Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`, "");
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`);
/***************** Caches *****************/
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
if (typeof Caches?.Playlists !== "object" || Array.isArray(Caches?.Playlists)) Caches.Playlists = {}; // 创建Playlists缓存
Caches.Playlists.Master = new Map(JSON.parse(Caches?.Playlists?.Master || "[]")); // Strings转Array转Map
Caches.Playlists.Subtitle = new Map(JSON.parse(Caches?.Playlists?.Subtitle || "[]")); // Strings转Array转Map
if (typeof Caches?.Subtitles !== "object") Caches.Subtitles = new Map(JSON.parse(Caches?.Subtitles || "[]")); // Strings转Array转Map
//log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, "");
if (typeof Caches?.Metadatas !== "object" || Array.isArray(Caches?.Metadatas)) Caches.Metadatas = {}; // 创建Playlists缓存
if (typeof Caches?.Metadatas?.Tracks !== "object") Caches.Metadatas.Tracks = new Map(JSON.parse(Caches?.Metadatas?.Tracks || "[]")); // Strings转Array转Map
/***************** Configs *****************/
Console.log("✅ Set Environment Variables");
return { Settings, Caches, Configs };
};
8 changes: 0 additions & 8 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
export interface Settings {
/**
* 总功能开关
*
* 是否启用此APP修改
*
* @defaultValue true
*/
Switch?: boolean;
}
2 changes: 1 addition & 1 deletion template/boxjs.settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"@DualSubs.AddOn.Settings.Switch","name":"总功能开关","type":"boolean","val":true,"desc":"是否启用此APP修改"}]
[]
26 changes: 0 additions & 26 deletions template/egern.handlebars

This file was deleted.

0 comments on commit 595cfe8

Please sign in to comment.