Skip to content

Commit fed2524

Browse files
committed
refactor: 清理请求和响应处理逻辑,移除冗余代码
1 parent 9838ab1 commit fed2524

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

src/request.dev.js

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,16 @@ Console.info(`PLATFORM: ${PLATFORM}`);
8282
let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array());
8383
//Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody, null, 2)}`);
8484
switch (url.hostname) {
85-
case "gsp-ssl.ls.apple.com":
8685
case "dispatcher.is.autonavi.com":
8786
switch (url.pathname) {
88-
case "/dispatcher.arpc":
8987
case "/dispatcher": {
90-
/****************** initialization start *******************/
91-
// 先拆分aRPC校验头和protobuf数据体
92-
const headerIndex = rawBody.findIndex((element, index) => element === 0x0a && index > 47);
93-
Console.debug(`headerIndex: ${headerIndex}`);
94-
const Header = rawBody.slice(0, headerIndex);
95-
body = rawBody.slice(headerIndex);
96-
/****************** initialization finish *******************/
97-
body = GEOPDPlaceRequest.decode(body);
98-
Console.debug(`body: ${JSON.stringify(body, null, 2)}`);
99-
switch (body.requestType) {
100-
case "REQUEST_TYPE_REVERSE_GEOCODING":
101-
break;
102-
}
103-
body.displayRegion = "US";
104-
body.clientMetadata.deviceCountryCode = "US";
105-
body = GEOPDPlaceRequest.encode(body);
106-
/****************** initialization start *******************/
107-
rawBody = new Uint8Array(Header.length + body.length);
108-
rawBody.set(Header, 0);
109-
rawBody.set(body, Header.length);
110-
/****************** initialization finish *******************/
88+
break;
89+
}
90+
}
91+
break;
92+
case "gsp-ssl.ls.apple.com":
93+
switch (url.pathname) {
94+
case "/dispatcher.arpc": {
11195
break;
11296
}
11397
}
@@ -137,19 +121,6 @@ Console.info(`PLATFORM: ${PLATFORM}`);
137121
case "gspe1-ssl.ls.apple.com":
138122
switch (url.pathname) {
139123
case "/pep/gcc":
140-
/* // 不使用 echo response
141-
$response = {
142-
status: 200,
143-
headers: {
144-
"Content-Type": "text/html",
145-
Date: new Date().toUTCString(),
146-
Connection: "keep-alive",
147-
"Content-Encoding": "identity",
148-
},
149-
body: Settings.PEP.GCC,
150-
};
151-
Console.debug(JSON.stringify($response));
152-
*/
153124
break;
154125
}
155126
break;

src/response.dev.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Console.info(`PATHs: ${PATHs}`);
1515
// 解析格式
1616
const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0];
1717
Console.info(`FORMAT: ${FORMAT}`);
18-
const PLATFORM = ["Location", "Maps"];
18+
const PLATFORM = ["Maps"];
1919
if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch");
2020
Console.info(`PLATFORM: ${PLATFORM}`);
2121
(async () => {
@@ -57,15 +57,6 @@ Console.info(`PLATFORM: ${PLATFORM}`);
5757
// 路径判断
5858
switch (url.pathname) {
5959
case "/pep/gcc":
60-
_.set(Caches, "pep.gcc", $response.body);
61-
Storage.setItem("@iRingo.Location.Caches", Caches);
62-
switch (Settings.PEP.GCC) {
63-
case "AUTO":
64-
break;
65-
default:
66-
$response.body = Settings.PEP.GCC;
67-
break;
68-
}
6960
break;
7061
}
7162
//$repsonse.body = new XMLSerializer().serializeToString(body);

0 commit comments

Comments
 (0)