Skip to content

Commit

Permalink
feat: Console.logLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
VirgilClyne committed Dec 9, 2024
1 parent ab9c536 commit 28ae831
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
15 changes: 15 additions & 0 deletions arguments-builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,20 @@ export default defineConfig({
],
type: "string",
},
{
key: "LogLevel",
name: "[调试] 日志等级",
type: "string",
description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。",
defaultValue: "WARN",
options: [
{ key: "OFF", label: "关闭" },
{ key: "ERROR", label: "❌ 错误" },
{ key: "WARN", label: "⚠️ 警告" },
{ key: "INFO", label: "ℹ️ 信息" },
{ key: "DEBUG", label: "🅱️ 调试" },
{ key: "ALL", label: "全部" },
],
},
],
});
22 changes: 11 additions & 11 deletions src/request.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import GEOPDPlaceRequest from "./class/GEOPDPlaceRequest.mjs";
// 构造回复数据
// biome-ignore lint/style/useConst: <explanation>
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}`);
Expand All @@ -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":
Expand Down Expand Up @@ -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 *******************/
Expand Down Expand Up @@ -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 = {
Expand All @@ -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":
Expand Down
15 changes: 7 additions & 8 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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 = {};
// 方法判断
Expand Down Expand Up @@ -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 = {
Expand All @@ -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":
Expand Down
18 changes: 9 additions & 9 deletions src/response.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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 = {};
// 格式判断
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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": {
Expand Down
17 changes: 8 additions & 9 deletions src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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 = {};
// 格式判断
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 28ae831

Please sign in to comment.