Skip to content

Commit 4d9aca8

Browse files
committed
feat: Console.logLevel
Update arguments-builder.config.ts Update response.dev.js Update request.dev.js Update response.js Update request.js
1 parent ab9c536 commit 4d9aca8

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

arguments-builder.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,20 @@ export default defineConfig({
140140
],
141141
type: "string",
142142
},
143+
{
144+
key: "LogLevel",
145+
name: "[调试] 日志等级",
146+
type: "string",
147+
defaultValue: "WARN",
148+
description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。",
149+
options: [
150+
{ key: "OFF", label: "关闭" },
151+
{ key: "ERROR", label: "❌ 错误" },
152+
{ key: "WARN", label: "⚠️ 警告" },
153+
{ key: "INFO", label: "ℹ️ 信息" },
154+
{ key: "DEBUG", label: "🅱️ 调试" },
155+
{ key: "ALL", label: "全部" },
156+
],
157+
},
143158
],
144159
});

src/request.dev.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import GEOPDPlaceRequest from "./class/GEOPDPlaceRequest.mjs";
55
// 构造回复数据
66
// biome-ignore lint/style/useConst: <explanation>
77
let $response = undefined;
8+
Console.logLevel = "DEBUG";
89
/***************** Processing *****************/
910
// 解构URL
1011
const url = new URL($request.url);
1112
Console.info(`url: ${url.toJSON()}`);
1213
// 获取连接参数
13-
const METHOD = $request.method,
14-
HOST = url.hostname,
15-
PATH = url.pathname;
16-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
14+
const PATHs = url.pathname.split("/").filter(Boolean);
15+
Console.info(`PATHs: ${PATHs}`);
1716
// 解析格式
1817
const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0];
1918
Console.info(`FORMAT: ${FORMAT}`);
@@ -26,10 +25,11 @@ Console.info(`PLATFORM: ${PLATFORM}`);
2625
* @type {{Settings: import('./types').Settings}}
2726
*/
2827
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
28+
Console.logLevel = Settings.LogLevel;
2929
// 创建空数据
3030
let body = {};
3131
// 方法判断
32-
switch (METHOD) {
32+
switch ($request.method) {
3333
case "POST":
3434
case "PUT":
3535
case "PATCH":
@@ -82,10 +82,10 @@ Console.info(`PLATFORM: ${PLATFORM}`);
8282
//Console.debug(`$request: ${JSON.stringify($request, null, 2)}`);
8383
let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array());
8484
//Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody, null, 2)}`);
85-
switch (HOST) {
85+
switch (url.hostname) {
8686
case "gsp-ssl.ls.apple.com":
8787
case "dispatcher.is.autonavi.com":
88-
switch (PATH) {
88+
switch (url.pathname) {
8989
case "/dispatcher.arpc":
9090
case "/dispatcher": {
9191
/****************** initialization start *******************/
@@ -127,16 +127,16 @@ Console.info(`PLATFORM: ${PLATFORM}`);
127127
delete $request?.headers?.["If-None-Match"];
128128
delete $request?.headers?.["if-none-match"];
129129
// 主机判断
130-
switch (HOST) {
130+
switch (url.hostname) {
131131
case "configuration.ls.apple.com":
132132
// 路径判断
133-
switch (PATH) {
133+
switch (url.pathname) {
134134
case "/config/defaults":
135135
break;
136136
}
137137
break;
138138
case "gspe1-ssl.ls.apple.com":
139-
switch (PATH) {
139+
switch (url.pathname) {
140140
case "/pep/gcc":
141141
/* // 不使用 echo response
142142
$response = {
@@ -156,7 +156,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
156156
break;
157157
case "gspe35-ssl.ls.apple.com":
158158
case "gspe35-ssl.ls.apple.cn":
159-
switch (PATH) {
159+
switch (url.pathname) {
160160
case "/config/announcements":
161161
switch (Settings?.Config?.Announcements?.Environment) {
162162
case "AUTO":

src/request.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ let $response = undefined;
99
const url = new URL($request.url);
1010
Console.info(`url: ${url.toJSON()}`);
1111
// 获取连接参数
12-
const METHOD = $request.method,
13-
HOST = url.hostname,
14-
PATH = url.pathname;
15-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
12+
const PATHs = url.pathname.split("/").filter(Boolean);
13+
Console.info(`PATHs: ${PATHs}`);
1614
// 解析格式
1715
const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0];
1816
Console.info(`FORMAT: ${FORMAT}`);
@@ -25,6 +23,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
2523
* @type {{Settings: import('./types').Settings}}
2624
*/
2725
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
26+
Console.logLevel = Settings.LogLevel;
2827
// 创建空数据
2928
let body = {};
3029
// 方法判断
@@ -94,16 +93,16 @@ Console.info(`PLATFORM: ${PLATFORM}`);
9493
delete $request?.headers?.["If-None-Match"];
9594
delete $request?.headers?.["if-none-match"];
9695
// 主机判断
97-
switch (HOST) {
96+
switch (url.hostname) {
9897
case "configuration.ls.apple.com":
9998
// 路径判断
100-
switch (PATH) {
99+
switch (url.pathname) {
101100
case "/config/defaults":
102101
break;
103102
}
104103
break;
105104
case "gspe1-ssl.ls.apple.com":
106-
switch (PATH) {
105+
switch (url.pathname) {
107106
case "/pep/gcc":
108107
/* // 不使用 echo response
109108
$response = {
@@ -123,7 +122,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
123122
break;
124123
case "gspe35-ssl.ls.apple.com":
125124
case "gspe35-ssl.ls.apple.cn":
126-
switch (PATH) {
125+
switch (url.pathname) {
127126
case "/config/announcements":
128127
switch (Settings?.Config?.Announcements?.Environment) {
129128
case "AUTO":

src/response.dev.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import setENV from "./function/setENV.mjs";
55
import GEOResourceManifest from "./class/GEOResourceManifest.mjs";
66
import GEOResourceManifestDownload from "./class/GEOResourceManifestDownload.mjs";
77
import { BinaryReader, UnknownFieldHandler } from "@protobuf-ts/runtime";
8+
Console.logLevel = "DEBUG";
89
/***************** Processing *****************/
910
// 解构URL
1011
const url = new URL($request.url);
1112
Console.info(`url: ${url.toJSON()}`);
1213
// 获取连接参数
13-
const METHOD = $request.method,
14-
HOST = url.hostname,
15-
PATH = url.pathname;
16-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
14+
const PATHs = url.pathname.split("/").filter(Boolean);
15+
Console.info(`PATHs: ${PATHs}`);
1716
// 解析格式
1817
const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0];
1918
Console.info(`FORMAT: ${FORMAT}`);
@@ -26,6 +25,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
2625
* @type {{Settings: import('./types').Settings}}
2726
*/
2827
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
28+
Console.logLevel = Settings.LogLevel;
2929
// 创建空数据
3030
let body = {};
3131
// 格式判断
@@ -52,11 +52,11 @@ Console.info(`PLATFORM: ${PLATFORM}`);
5252
case "application/plist":
5353
case "application/x-plist":
5454
// 主机判断
55-
switch (HOST) {
55+
switch (url.hostname) {
5656
case "gspe1-ssl.ls.apple.com":
5757
//body = new DOMParser().parseFromString($response.body, FORMAT);
5858
// 路径判断
59-
switch (PATH) {
59+
switch (url.pathname) {
6060
case "/pep/gcc":
6161
_.set(Caches, "pep.gcc", $response.body);
6262
Storage.setItem("@iRingo.Location.Caches", Caches);
@@ -79,7 +79,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
7979
body = XML.parse($response.body);
8080
Console.debug(`body: ${JSON.stringify(body)}`);
8181
// 路径判断
82-
switch (PATH) {
82+
switch (url.pathname) {
8383
case "/config/defaults": {
8484
const PLIST = body.plist;
8585
if (PLIST) {
@@ -144,9 +144,9 @@ Console.info(`PLATFORM: ${PLATFORM}`);
144144
case "application/x-protobuf":
145145
case "application/vnd.google.protobuf":
146146
case "application/octet-stream":
147-
switch (HOST) {
147+
switch (url.hostname) {
148148
case "gspe35-ssl.ls.apple.com":
149-
switch (PATH) {
149+
switch (url.pathname) {
150150
case "/config/announcements":
151151
break;
152152
case "/geo_manifest/dynamic/config": {

src/response.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import GEOResourceManifestDownload from "./class/GEOResourceManifestDownload.mjs
99
const url = new URL($request.url);
1010
Console.info(`url: ${url.toJSON()}`);
1111
// 获取连接参数
12-
const METHOD = $request.method,
13-
HOST = url.hostname,
14-
PATH = url.pathname;
15-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
12+
const PATHs = url.pathname.split("/").filter(Boolean);
13+
Console.info(`PATHs: ${PATHs}`);
1614
// 解析格式
1715
const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0];
1816
Console.info(`FORMAT: ${FORMAT}`);
@@ -25,6 +23,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
2523
* @type {{Settings: import('./types').Settings}}
2624
*/
2725
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
26+
Console.logLevel = Settings.LogLevel;
2827
// 创建空数据
2928
let body = {};
3029
// 格式判断
@@ -47,11 +46,11 @@ Console.info(`PLATFORM: ${PLATFORM}`);
4746
case "application/plist":
4847
case "application/x-plist":
4948
// 主机判断
50-
switch (HOST) {
49+
switch (url.hostname) {
5150
case "gspe1-ssl.ls.apple.com":
5251
//body = new DOMParser().parseFromString($response.body, FORMAT);
5352
// 路径判断
54-
switch (PATH) {
53+
switch (url.pathname) {
5554
case "/pep/gcc":
5655
_.set(Caches, "pep.gcc", $response.body);
5756
Storage.setItem("@iRingo.Location.Caches", Caches);
@@ -71,7 +70,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
7170
};
7271
body = XML.parse($response.body);
7372
// 路径判断
74-
switch (PATH) {
73+
switch (url.pathname) {
7574
case "/config/defaults": {
7675
const PLIST = body.plist;
7776
if (PLIST) {
@@ -129,9 +128,9 @@ Console.info(`PLATFORM: ${PLATFORM}`);
129128
case "application/x-protobuf":
130129
case "application/vnd.google.protobuf":
131130
case "application/octet-stream":
132-
switch (HOST) {
131+
switch (url.hostname) {
133132
case "gspe35-ssl.ls.apple.com":
134-
switch (PATH) {
133+
switch (url.pathname) {
135134
case "/config/announcements":
136135
break;
137136
case "/geo_manifest/dynamic/config": {

0 commit comments

Comments
 (0)