Skip to content

Commit

Permalink
feat: Console
Browse files Browse the repository at this point in the history
Update CHANGELOG.md
Update response.dev.js
Update request.dev.js
Update response.js
Update setENV.mjs
Update request.js
  • Loading branch information
VirgilClyne committed Nov 29, 2024
1 parent c8aba82 commit ec5471d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 185 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
* 升级了 `@nsnanocat/util`
* `util``submodule` 更改为 `package`
* `$platform` 改为 `$app`
* 使用了全新的 `Console` polyfill
9 changes: 5 additions & 4 deletions src/function/setENV.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lodash as _, getStorage, log } from "@nsnanocat/util";
import { Console, getStorage, Lodash as _ } from "@nsnanocat/util";

/**
* Set Environment Variables
Expand All @@ -9,12 +9,13 @@ import { Lodash as _, getStorage, log } from "@nsnanocat/util";
* @return {Object} { Settings, Caches, Configs }
*/
export default function setENV(name, platforms, database) {
log("☑️ Set Environment Variables", "");
Console.log("☑️ Set Environment Variables");
const { Settings, Caches, Configs } = getStorage(name, platforms, database);
/***************** Settings *****************/
log(`✅ Set Environment Variables, Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`, "");
Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings)}`);
/***************** Caches *****************/
//log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, "");
//Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`);
/***************** Configs *****************/
Console.log("✅ Set Environment Variables");
return { Settings, Caches, Configs };
};
38 changes: 19 additions & 19 deletions src/request.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Console, done, fetch, gRPC, Lodash as _, notification, Storage, wait } from "@nsnanocat/util";
import database from "./function/database.mjs";
import setENV from "./function/setENV.mjs";
import MD5 from "crypto-js/md5.js";
Expand All @@ -8,13 +8,13 @@ let $response = undefined;
/***************** Processing *****************/
// 解构URL
const url = new URL($request.url);
log(`⚠ url: ${url.toJSON()}`, "");
Console.info(`url: ${url.toJSON()}`);
// 获取连接参数
const PATHs = url.pathname.split("/").filter(Boolean);
log(`⚠ PATHs: ${PATHs}` , "");
Console.info(`PATHs: ${PATHs}` );
// 解析格式
const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0];
log(`⚠ FORMAT: ${FORMAT}`, "");
Console.info(`FORMAT: ${FORMAT}`);
!(async () => {
/**
* 设置
Expand Down Expand Up @@ -43,7 +43,7 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/vnd.apple.mpegurl":
case "audio/mpegurl":
//body = M3U8.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = M3U8.stringify(body);
break;
case "text/xml":
Expand All @@ -53,19 +53,19 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/plist":
case "application/x-plist":
//body = XML.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = XML.stringify(body);
break;
case "text/vtt":
case "application/vtt":
//body = VTT.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = VTT.stringify(body);
break;
case "text/json":
case "application/json":
//body = JSON.parse($request.body ?? "{}");
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = JSON.stringify(body);
break;
case "application/protobuf":
Expand All @@ -74,9 +74,9 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/grpc":
case "application/grpc+proto":
case "applecation/octet-stream": {
//log(`🚧 $request.body: ${JSON.stringify($request.body)}`, "");
//Console.debug(`$request.body: ${JSON.stringify($request.body)}`);
//let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array());
//log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, "");
//Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`);
break;
}
}
Expand Down Expand Up @@ -112,11 +112,11 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
if (url.searchParams.get("login_event") !== "0") {
// 此字段可区分第一次请求和后续请求
url.searchParams.delete("sign");
url.searchParams.set("open_event", "");
url.searchParams.set("open_event");
url.searchParams.set("pull", 0);
if (Caches.banner_hash) {
url.searchParams.set("banner_hash", Caches.banner_hash);
log("🎉 读取hash缓存成功");
Console.log(" 读取hash缓存成功");
}
const string = `${url.search.substring(1)}c2ed53a74eeefe3cf99fbd01d8c9c375`;
const sign = MD5(string).toString();
Expand All @@ -125,12 +125,12 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
}
break;
case false:
log("🚧 用户设置推荐页活动大图不去除");
Console.warn("用户设置推荐页活动大图不去除");
break;
}
break;
case false:
log("🚧 用户设置推荐页广告不去除");
Console.warn("用户设置推荐页广告不去除");
break;
}
break;
Expand Down Expand Up @@ -170,13 +170,13 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
break;
}
$request.url = url.toString();
log("🚧 调试信息", `$request.url: ${$request.url}`, "");
Console.debug(`$request.url: ${$request.url}`);
})()
.catch(e => logError(e))
.catch(e => Console.error(e))
.finally(() => {
switch (typeof $response) {
case "object": // 有构造回复数据,返回构造的回复数据
//log("🚧 finally", `echo $response: ${JSON.stringify($response, null, 2)}`, "");
//Console.debug("finally", `echo $response: ${JSON.stringify($response, null, 2)}`);
if ($response.headers?.["Content-Encoding"]) $response.headers["Content-Encoding"] = "identity";
if ($response.headers?.["content-encoding"]) $response.headers["content-encoding"] = "identity";
switch ($app) {
Expand All @@ -193,11 +193,11 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
}
break;
case "undefined": // 无构造回复数据,发送修改的请求数据
//log("🚧 finally", `$request: ${JSON.stringify($request, null, 2)}`, "");
//Console.debug("finally", `$request: ${JSON.stringify($request, null, 2)}`);
done($request);
break;
default:
logError(`不合法的 $response 类型: ${typeof $response}`, "");
Console.error(`不合法的 $response 类型: ${typeof $response}`);
break;
}
});
39 changes: 20 additions & 19 deletions src/request.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util";
import { $app, Console, done, fetch, gRPC, Lodash as _, notification, Storage, wait } from "@nsnanocat/util";
import database from "./function/database.mjs";
import setENV from "./function/setENV.mjs";
import MD5 from "crypto-js/md5.js";
// 构造回复数据
// biome-ignore lint/style/useConst: <explanation>
let $response = undefined;
Console.debug = () => {};
/***************** Processing *****************/
// 解构URL
const url = new URL($request.url);
log(`⚠ url: ${url.toJSON()}`, "");
Console.info(`url: ${url.toJSON()}`);
// 获取连接参数
const PATHs = url.pathname.split("/").filter(Boolean);
log(`⚠ PATHs: ${PATHs}` , "");
Console.info(`PATHs: ${PATHs}` );
// 解析格式
const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0];
log(`⚠ FORMAT: ${FORMAT}`, "");
Console.info(`FORMAT: ${FORMAT}`);
!(async () => {
/**
* 设置
Expand Down Expand Up @@ -43,7 +44,7 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/vnd.apple.mpegurl":
case "audio/mpegurl":
//body = M3U8.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = M3U8.stringify(body);
break;
case "text/xml":
Expand All @@ -53,19 +54,19 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/plist":
case "application/x-plist":
//body = XML.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = XML.stringify(body);
break;
case "text/vtt":
case "application/vtt":
//body = VTT.parse($request.body);
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = VTT.stringify(body);
break;
case "text/json":
case "application/json":
//body = JSON.parse($request.body ?? "{}");
//log(`🚧 body: ${JSON.stringify(body)}`, "");
//Console.debug(`body: ${JSON.stringify(body)}`);
//$request.body = JSON.stringify(body);
break;
case "application/protobuf":
Expand All @@ -74,9 +75,9 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
case "application/grpc":
case "application/grpc+proto":
case "applecation/octet-stream": {
//log(`🚧 $request.body: ${JSON.stringify($request.body)}`, "");
//Console.debug(`$request.body: ${JSON.stringify($request.body)}`);
//let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array());
//log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, "");
//Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`);
break;
}
}
Expand Down Expand Up @@ -112,11 +113,11 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
if (url.searchParams.get("login_event") !== "0") {
// 此字段可区分第一次请求和后续请求
url.searchParams.delete("sign");
url.searchParams.set("open_event", "");
url.searchParams.set("open_event");
url.searchParams.set("pull", 0);
if (Caches.banner_hash) {
url.searchParams.set("banner_hash", Caches.banner_hash);
log("🎉 读取hash缓存成功");
Console.log(" 读取hash缓存成功");
}
const string = `${url.search.substring(1)}c2ed53a74eeefe3cf99fbd01d8c9c375`;
const sign = MD5(string).toString();
Expand All @@ -125,12 +126,12 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
}
break;
case false:
log("🚧 用户设置推荐页活动大图不去除");
Console.warn("用户设置推荐页活动大图不去除");
break;
}
break;
case false:
log("🚧 用户设置推荐页广告不去除");
Console.warn("用户设置推荐页广告不去除");
break;
}
break;
Expand Down Expand Up @@ -170,13 +171,13 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
break;
}
$request.url = url.toString();
log("🚧 调试信息", `$request.url: ${$request.url}`, "");
Console.debug(`$request.url: ${$request.url}`);
})()
.catch(e => logError(e))
.catch(e => Console.error(e))
.finally(() => {
switch (typeof $response) {
case "object": // 有构造回复数据,返回构造的回复数据
//log("🚧 finally", `echo $response: ${JSON.stringify($response, null, 2)}`, "");
//Console.debug("finally", `echo $response: ${JSON.stringify($response, null, 2)}`);
if ($response.headers?.["Content-Encoding"]) $response.headers["Content-Encoding"] = "identity";
if ($response.headers?.["content-encoding"]) $response.headers["content-encoding"] = "identity";
switch ($app) {
Expand All @@ -193,11 +194,11 @@ log(`⚠ FORMAT: ${FORMAT}`, "");
}
break;
case "undefined": // 无构造回复数据,发送修改的请求数据
//log("🚧 finally", `$request: ${JSON.stringify($request, null, 2)}`, "");
//Console.debug("finally", `$request: ${JSON.stringify($request, null, 2)}`);
done($request);
break;
default:
logError(`不合法的 $response 类型: ${typeof $response}`, "");
Console.error(`不合法的 $response 类型: ${typeof $response}`);
break;
}
});
Loading

0 comments on commit ec5471d

Please sign in to comment.