diff --git a/arguments-builder.config.ts b/arguments-builder.config.ts index 47d06f6..5db01ba 100644 --- a/arguments-builder.config.ts +++ b/arguments-builder.config.ts @@ -140,5 +140,20 @@ export default defineConfig({ ], type: "string", }, + { + key: "LogLevel", + name: "[调试] 日志等级", + type: "string", + defaultValue: "WARN", + description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。", + options: [ + { key: "OFF", label: "关闭" }, + { key: "ERROR", label: "❌ 错误" }, + { key: "WARN", label: "⚠️ 警告" }, + { key: "INFO", label: "ℹ️ 信息" }, + { key: "DEBUG", label: "🅱️ 调试" }, + { key: "ALL", label: "全部" }, + ], + }, ], }); diff --git a/src/request.dev.js b/src/request.dev.js index 7e911db..84acf98 100644 --- a/src/request.dev.js +++ b/src/request.dev.js @@ -5,15 +5,14 @@ import GEOPDPlaceRequest from "./class/GEOPDPlaceRequest.mjs"; // 构造回复数据 // biome-ignore lint/style/useConst: let $response = undefined; +Console.logLevel = "DEBUG"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); @@ -26,10 +25,11 @@ Console.info(`PLATFORM: ${PLATFORM}`); * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 方法判断 - switch (METHOD) { + switch ($request.method) { case "POST": case "PUT": case "PATCH": @@ -82,10 +82,10 @@ Console.info(`PLATFORM: ${PLATFORM}`); //Console.debug(`$request: ${JSON.stringify($request, null, 2)}`); let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array()); //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody, null, 2)}`); - switch (HOST) { + switch (url.hostname) { case "gsp-ssl.ls.apple.com": case "dispatcher.is.autonavi.com": - switch (PATH) { + switch (url.pathname) { case "/dispatcher.arpc": case "/dispatcher": { /****************** initialization start *******************/ @@ -127,16 +127,16 @@ Console.info(`PLATFORM: ${PLATFORM}`); delete $request?.headers?.["If-None-Match"]; delete $request?.headers?.["if-none-match"]; // 主机判断 - switch (HOST) { + switch (url.hostname) { case "configuration.ls.apple.com": // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": break; } break; case "gspe1-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": /* // 不使用 echo response $response = { @@ -156,7 +156,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); break; case "gspe35-ssl.ls.apple.com": case "gspe35-ssl.ls.apple.cn": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": switch (Settings?.Config?.Announcements?.Environment) { case "AUTO": diff --git a/src/request.js b/src/request.js index 7a30f19..12d6644 100644 --- a/src/request.js +++ b/src/request.js @@ -9,10 +9,8 @@ let $response = undefined; const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); @@ -25,6 +23,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 方法判断 @@ -94,16 +93,16 @@ Console.info(`PLATFORM: ${PLATFORM}`); delete $request?.headers?.["If-None-Match"]; delete $request?.headers?.["if-none-match"]; // 主机判断 - switch (HOST) { + switch (url.hostname) { case "configuration.ls.apple.com": // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": break; } break; case "gspe1-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": /* // 不使用 echo response $response = { @@ -123,7 +122,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); break; case "gspe35-ssl.ls.apple.com": case "gspe35-ssl.ls.apple.cn": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": switch (Settings?.Config?.Announcements?.Environment) { case "AUTO": diff --git a/src/response.dev.js b/src/response.dev.js index 0d08a5e..bb6a8ea 100644 --- a/src/response.dev.js +++ b/src/response.dev.js @@ -5,15 +5,14 @@ import setENV from "./function/setENV.mjs"; import GEOResourceManifest from "./class/GEOResourceManifest.mjs"; import GEOResourceManifestDownload from "./class/GEOResourceManifestDownload.mjs"; import { BinaryReader, UnknownFieldHandler } from "@protobuf-ts/runtime"; +Console.logLevel = "DEBUG"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); @@ -26,6 +25,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 格式判断 @@ -52,11 +52,11 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/plist": case "application/x-plist": // 主机判断 - switch (HOST) { + switch (url.hostname) { case "gspe1-ssl.ls.apple.com": //body = new DOMParser().parseFromString($response.body, FORMAT); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": _.set(Caches, "pep.gcc", $response.body); Storage.setItem("@iRingo.Location.Caches", Caches); @@ -79,7 +79,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); body = XML.parse($response.body); Console.debug(`body: ${JSON.stringify(body)}`); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": { const PLIST = body.plist; if (PLIST) { @@ -144,9 +144,9 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/x-protobuf": case "application/vnd.google.protobuf": case "application/octet-stream": - switch (HOST) { + switch (url.hostname) { case "gspe35-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": break; case "/geo_manifest/dynamic/config": { diff --git a/src/response.js b/src/response.js index ba7c2a0..cd64673 100644 --- a/src/response.js +++ b/src/response.js @@ -9,10 +9,8 @@ import GEOResourceManifestDownload from "./class/GEOResourceManifestDownload.mjs const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); @@ -25,6 +23,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 格式判断 @@ -47,11 +46,11 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/plist": case "application/x-plist": // 主机判断 - switch (HOST) { + switch (url.hostname) { case "gspe1-ssl.ls.apple.com": //body = new DOMParser().parseFromString($response.body, FORMAT); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": _.set(Caches, "pep.gcc", $response.body); Storage.setItem("@iRingo.Location.Caches", Caches); @@ -71,7 +70,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); }; body = XML.parse($response.body); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": { const PLIST = body.plist; if (PLIST) { @@ -129,9 +128,9 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/x-protobuf": case "application/vnd.google.protobuf": case "application/octet-stream": - switch (HOST) { + switch (url.hostname) { case "gspe35-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": break; case "/geo_manifest/dynamic/config": {