Skip to content

Commit a6b5e1d

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

File tree

6 files changed

+53
-42
lines changed

6 files changed

+53
-42
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/function/setENV.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ 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-
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
15+
Console.info(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`);
1616
/***************** Caches *****************/
1717
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
1818
/***************** Configs *****************/

src/request.dev.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,25 @@ let $response = undefined;
1010
const url = new URL($request.url);
1111
Console.info(`url: ${url.toJSON()}`);
1212
// 获取连接参数
13-
const METHOD = $request.method,
14-
HOST = url.hostname,
15-
PATH = url.pathname;
16-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
13+
const PATHs = url.pathname.split("/").filter(Boolean);
14+
Console.info(`PATHs: ${PATHs}`);
1715
// 解析格式
1816
const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0];
1917
Console.info(`FORMAT: ${FORMAT}`);
2018
const PLATFORM = ["Maps"];
2119
if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch");
2220
Console.info(`PLATFORM: ${PLATFORM}`);
23-
!(async () => {
21+
(async () => {
2422
/**
2523
* 设置
2624
* @type {{Settings: import('./types').Settings}}
2725
*/
2826
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
27+
Console.logLevel = Settings.LogLevel;
2928
// 创建空数据
3029
let body = {};
3130
// 方法判断
32-
switch (METHOD) {
31+
switch ($request.method) {
3332
case "POST":
3433
case "PUT":
3534
case "PATCH":
@@ -82,10 +81,10 @@ Console.info(`PLATFORM: ${PLATFORM}`);
8281
//Console.debug(`$request: ${JSON.stringify($request, null, 2)}`);
8382
let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array());
8483
//Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody, null, 2)}`);
85-
switch (HOST) {
84+
switch (url.hostname) {
8685
case "gsp-ssl.ls.apple.com":
8786
case "dispatcher.is.autonavi.com":
88-
switch (PATH) {
87+
switch (url.pathname) {
8988
case "/dispatcher.arpc":
9089
case "/dispatcher": {
9190
/****************** initialization start *******************/
@@ -127,16 +126,16 @@ Console.info(`PLATFORM: ${PLATFORM}`);
127126
delete $request?.headers?.["If-None-Match"];
128127
delete $request?.headers?.["if-none-match"];
129128
// 主机判断
130-
switch (HOST) {
129+
switch (url.hostname) {
131130
case "configuration.ls.apple.com":
132131
// 路径判断
133-
switch (PATH) {
132+
switch (url.pathname) {
134133
case "/config/defaults":
135134
break;
136135
}
137136
break;
138137
case "gspe1-ssl.ls.apple.com":
139-
switch (PATH) {
138+
switch (url.pathname) {
140139
case "/pep/gcc":
141140
/* // 不使用 echo response
142141
$response = {
@@ -156,7 +155,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
156155
break;
157156
case "gspe35-ssl.ls.apple.com":
158157
case "gspe35-ssl.ls.apple.cn":
159-
switch (PATH) {
158+
switch (url.pathname) {
160159
case "/config/announcements":
161160
switch (Settings?.Config?.Announcements?.Environment) {
162161
case "AUTO":

src/request.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ 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}`);
1917
const PLATFORM = ["Maps"];
2018
if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch");
2119
Console.info(`PLATFORM: ${PLATFORM}`);
22-
!(async () => {
20+
(async () => {
2321
/**
2422
* 设置
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ import { BinaryReader, UnknownFieldHandler } from "@protobuf-ts/runtime";
1010
const url = new URL($request.url);
1111
Console.info(`url: ${url.toJSON()}`);
1212
// 获取连接参数
13-
const METHOD = $request.method,
14-
HOST = url.hostname,
15-
PATH = url.pathname;
16-
Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`);
13+
const PATHs = url.pathname.split("/").filter(Boolean);
14+
Console.info(`PATHs: ${PATHs}`);
1715
// 解析格式
1816
const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0];
1917
Console.info(`FORMAT: ${FORMAT}`);
2018
const PLATFORM = ["Location", "Maps"];
2119
if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch");
2220
Console.info(`PLATFORM: ${PLATFORM}`);
23-
!(async () => {
21+
(async () => {
2422
/**
2523
* 设置
2624
* @type {{Settings: import('./types').Settings}}
2725
*/
2826
const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database);
27+
Console.logLevel = Settings.LogLevel;
2928
// 创建空数据
3029
let body = {};
3130
// 格式判断
@@ -52,11 +51,11 @@ Console.info(`PLATFORM: ${PLATFORM}`);
5251
case "application/plist":
5352
case "application/x-plist":
5453
// 主机判断
55-
switch (HOST) {
54+
switch (url.hostname) {
5655
case "gspe1-ssl.ls.apple.com":
5756
//body = new DOMParser().parseFromString($response.body, FORMAT);
5857
// 路径判断
59-
switch (PATH) {
58+
switch (url.pathname) {
6059
case "/pep/gcc":
6160
_.set(Caches, "pep.gcc", $response.body);
6261
Storage.setItem("@iRingo.Location.Caches", Caches);
@@ -79,7 +78,7 @@ Console.info(`PLATFORM: ${PLATFORM}`);
7978
body = XML.parse($response.body);
8079
Console.debug(`body: ${JSON.stringify(body)}`);
8180
// 路径判断
82-
switch (PATH) {
81+
switch (url.pathname) {
8382
case "/config/defaults": {
8483
const PLIST = body.plist;
8584
if (PLIST) {
@@ -144,9 +143,9 @@ Console.info(`PLATFORM: ${PLATFORM}`);
144143
case "application/x-protobuf":
145144
case "application/vnd.google.protobuf":
146145
case "application/octet-stream":
147-
switch (HOST) {
146+
switch (url.hostname) {
148147
case "gspe35-ssl.ls.apple.com":
149-
switch (PATH) {
148+
switch (url.pathname) {
150149
case "/config/announcements":
151150
break;
152151
case "/geo_manifest/dynamic/config": {

src/response.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ 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}`);
1917
const PLATFORM = ["Location", "Maps"];
2018
if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch");
2119
Console.info(`PLATFORM: ${PLATFORM}`);
22-
!(async () => {
20+
(async () => {
2321
/**
2422
* 设置
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)