From 1000fc364e195cad5e59bf35e1cb54369ea78729 Mon Sep 17 00:00:00 2001 From: Virgil Clyne Date: Thu, 28 Nov 2024 14:46:45 +0800 Subject: [PATCH] feat: Console Update surge.handlebars Update CHANGELOG.md Update response.dev.js Update request.dev.js Update setENV.mjs Update request.js --- CHANGELOG.md | 1 + src/function/setENV.mjs | 9 +++++---- src/request.dev.js | 31 ++++++++++++++++--------------- src/request.js | 33 +++++++++++++++++---------------- src/response.dev.js | 30 +++++++++++++++--------------- template/surge.handlebars | 1 - 6 files changed, 54 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3a075..60ca1e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ * 升级了 `@nsnanocat/util` * `util` 由 `submodule` 更改为 `package` * `$platform` 改为 `$app` + * 使用了全新的 `Console` polyfill diff --git a/src/function/setENV.mjs b/src/function/setENV.mjs index 48d5d8a..25f02d2 100644 --- a/src/function/setENV.mjs +++ b/src/function/setENV.mjs @@ -1,4 +1,4 @@ -import { Lodash as _, getStorage, log } from "@nsnanocat/util"; +import { Lodash as _, getStorage, Console } from "@nsnanocat/util"; /** * Set Environment Variables @@ -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.info("☑️ 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(`Settings: ${typeof Settings}, Settings内容: ${JSON.stringify(Settings)}`); /***************** Caches *****************/ - //log(`✅ Set Environment Variables, Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`, ""); + //Console.debug(`Caches: ${typeof Caches}, Caches内容: ${JSON.stringify(Caches)}`); /***************** Configs *****************/ + Console.info("✅ Set Environment Variables"); return { Settings, Caches, Configs }; }; diff --git a/src/request.dev.js b/src/request.dev.js index 9262ecc..ddbea5b 100644 --- a/src/request.dev.js +++ b/src/request.dev.js @@ -1,19 +1,20 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done, gRPC } from "@nsnanocat/util"; +import { $app, Lodash as _, Storage, Console, fetch, notification, wait, done, gRPC } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import database from "./function/database.mjs"; import setENV from "./function/setENV.mjs"; // 构造回复数据 let $response = undefined; +Console.debug = (...msg) => { }; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.debug(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.debug(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.debug(`FORMAT: ${FORMAT}`); !(async () => { /** * 设置 @@ -42,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": @@ -52,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": @@ -74,9 +75,9 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/grpc+proto": case "application/vnd.apple.flatbuffer": case "application/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)}`); switch (FORMAT) { case "application/protobuf": case "application/x-protobuf": @@ -172,13 +173,13 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); } if ($request.headers?.Host) $request.headers.Host = url.hostname; $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) { @@ -195,11 +196,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; } }); diff --git a/src/request.js b/src/request.js index 4f9c4a3..b9a3592 100644 --- a/src/request.js +++ b/src/request.js @@ -1,19 +1,20 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done } from "@nsnanocat/util"; +import { $app, Lodash as _, Storage, Console, fetch, notification, wait, done } from "@nsnanocat/util"; import { URL } from "@nsnanocat/url"; import database from "./function/database.mjs"; import setENV from "./function/setENV.mjs"; // 构造回复数据 let $response = undefined; +Console.debug = (...msg) => { }; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -//log(`⚠ url: ${url.toJSON()}`, ""); +Console.debug(`url: ${url.toJSON()}`); // 获取连接参数 const PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ PATHs: ${PATHs}`, ""); +Console.debug(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; -//log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.debug(`FORMAT: ${FORMAT}`); !(async () => { /** * 设置 @@ -42,7 +43,7 @@ const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["conten 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": @@ -52,19 +53,19 @@ const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["conten 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": @@ -74,9 +75,9 @@ const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["conten case "application/grpc+proto": case "application/vnd.apple.flatbuffer": case "application/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)}`); switch (FORMAT) { case "application/protobuf": case "application/x-protobuf": @@ -170,13 +171,13 @@ const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["conten } if ($request.headers?.Host) $request.headers.Host = url.hostname; $request.url = url.toString(); - //log("🚧 调试信息", `$request.url: ${$request.url}`, ""); + Console.debug(`$request.url: ${$request.url}`); })() - .catch(e => logError(e)) - .finally(() => { +.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) { @@ -193,11 +194,11 @@ const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["conten } 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; } }); diff --git a/src/response.dev.js b/src/response.dev.js index 6d38d5a..97f8f0a 100644 --- a/src/response.dev.js +++ b/src/response.dev.js @@ -1,4 +1,4 @@ -import { $app, Lodash as _, Storage, fetch, notification, log, logError, wait, done, gRPC } from "@nsnanocat/util"; +import { $app, Lodash as _, Storage, Console, fetch, notification, wait, done, gRPC } from "@nsnanocat/util"; import database from "./function/database.mjs"; import setENV from "./function/setENV.mjs"; import { WireType, UnknownFieldHandler, reflectionMergePartial, MESSAGE_TYPE, MessageType, BinaryReader, isJsonObject, typeofJsonValue, jsonWriteOptions } from "@protobuf-ts/runtime/build/es2015/index.js"; @@ -6,15 +6,15 @@ import { Any } from "./protobuf/google/protobuf/any.js"; /***************** Processing *****************/ // 解构URL const url = new URL($request.url); -log(`⚠ url: ${url.toJSON()}`, ""); +Console.debug(`url: ${url.toJSON()}`, ""); // 获取连接参数 const HOST = url.hostname, PATH = url.pathname, PATHs = url.pathname.split("/").filter(Boolean); -log(`⚠ HOST: ${HOST}, PATH: ${PATH}`, ""); +Console.debug(`HOST: ${HOST}, PATH: ${PATH}`, ""); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; -log(`⚠ FORMAT: ${FORMAT}`, ""); +Console.debug(`FORMAT: ${FORMAT}`, ""); !(async () => { /** * 设置 @@ -48,7 +48,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/vnd.apple.mpegurl": case "audio/mpegurl": //body = M3U8.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`, ""); //$response.body = M3U8.stringify(body); break; case "text/xml": @@ -58,13 +58,13 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/plist": case "application/x-plist": //body = XML.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`, ""); //$response.body = XML.stringify(body); break; case "text/vtt": case "application/vtt": //body = VTT.parse($response.body); - //log(`🚧 body: ${JSON.stringify(body)}`, ""); + //Console.debug(`body: ${JSON.stringify(body)}`, ""); //$response.body = VTT.stringify(body); break; case "text/json": @@ -119,9 +119,9 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); case "application/grpc+proto": case "application/vnd.apple.flatbuffer": case "application/octet-stream": { - //log(`🚧 $response.body: ${JSON.stringify($response.body)}`, ""); + //Console.debug(`$response.body: ${JSON.stringify($response.body)}`, ""); let rawBody = $app === "Quantumult X" ? new Uint8Array($response.bodyBytes ?? []) : ($response.body ?? new Uint8Array()); - //log(`🚧 isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); + //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody)}`, ""); switch (FORMAT) { case "application/protobuf": case "application/x-protobuf": @@ -280,9 +280,9 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); const PlayViewUniteReply = new PlayViewUniteReply$Type(); /****************** initialization finish *******************/ let data = PlayViewUniteReply.fromBinary(body); - log(`🚧 data: ${JSON.stringify(data)}`, ""); + Console.debug(`data: ${JSON.stringify(data)}`, ""); let UF = UnknownFieldHandler.list(data); - //log(`🚧 UF: ${JSON.stringify(UF)}`, ""); + //Console.debug(`UF: ${JSON.stringify(UF)}`, ""); if (UF) { UF = UF.map(uf => { //uf.no; // 22 @@ -290,7 +290,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); // use the binary reader to decode the raw data: let reader = new BinaryReader(uf.data); let addedNumber = reader.int32(); // 7777 - log(`🚧 no: ${uf.no}, wireType: ${uf.wireType}, addedNumber: ${addedNumber}`, ""); + Console.debug(`no: ${uf.no}, wireType: ${uf.wireType}, addedNumber: ${addedNumber}`, ""); }); } data.vodInfo.streamList = data.vodInfo.streamList.map(stream => { @@ -307,7 +307,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); } return stream; }); - log(`🚧 data: ${JSON.stringify(data)}`, ""); + Console.debug(`data: ${JSON.stringify(data)}`, ""); body = PlayViewUniteReply.toBinary(data); break; } @@ -376,7 +376,7 @@ log(`⚠ FORMAT: ${FORMAT}`, ""); break; } } - log(`🚧 信息组, infoGroup: ${JSON.stringify(infoGroup)}`, ""); + Console.debug(`信息组, infoGroup: ${JSON.stringify(infoGroup)}`, ""); })() - .catch(e => logError(e)) + .catch(e => Console.error(e)) .finally(() => done($response)); diff --git a/template/surge.handlebars b/template/surge.handlebars index 30d9332..105ff8e 100644 --- a/template/surge.handlebars +++ b/template/surge.handlebars @@ -23,5 +23,4 @@ force-http-engine-hosts = %APPEND% *:4480, *.mcdn.bilivideo.cn:4483, *:8000, *:8 📺 BiliBili.Redirect.Akamaized.upgcxcode.m4s = type=http-request, pattern=^https?:\/\/upos-(hz|bstar1)-mirrorakam\.akamaized\.net/upgcxcode\/, engine=webview, script-path=https://github.com/BiliUniverse/Redirect/releases/download/v{{@package 'version'}}/request.bundle.js, argument={{{scriptParams}}} [MITM] -skip-server-cert-verify = true hostname = %APPEND% *.mcdn.bilivideo.cn, upos-sz-mirror*bstar1.bilivideo.com, upos-*-mirrorakam.akamaized.net