From 25d677be3d70e48ec61d0c9c3aac865e590889eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=84=86=E8=96=AF=E9=A5=BC?= Date: Mon, 9 Dec 2024 14:21:12 +0800 Subject: [PATCH] feat: Console.logLevel Update arguments-builder.config.ts Update boxjs.settings.json Update package-lock.json Update response.dev.js Update request.dev.js Update database.mjs Update response.js Update request.js Update setENV.mjs Update types.d.ts --- arguments-builder.config.ts | 15 ++ package-lock.json | 138 ++++------ package.json | 2 +- src/class/GEOPDPlaceRequest.mjs | 66 ++--- src/class/GEOResourceManifest.mjs | 4 +- src/class/GEOResourceManifestDownload.mjs | 218 +++++++++------- src/function/database.mjs | 305 ++++++++++++++++++---- src/function/setENV.mjs | 4 +- src/request.dev.js | 23 +- src/request.js | 19 +- src/response.dev.js | 19 +- src/response.js | 19 +- src/types.d.ts | 18 ++ template/boxjs.settings.json | 2 +- 14 files changed, 531 insertions(+), 321 deletions(-) diff --git a/arguments-builder.config.ts b/arguments-builder.config.ts index 47d06f6..5db01ba 100644 --- a/arguments-builder.config.ts +++ b/arguments-builder.config.ts @@ -140,5 +140,20 @@ export default defineConfig({ ], type: "string", }, + { + key: "LogLevel", + name: "[调试] 日志等级", + type: "string", + defaultValue: "WARN", + description: "选择脚本日志的输出等级,低于所选等级的日志将全部输出。", + options: [ + { key: "OFF", label: "关闭" }, + { key: "ERROR", label: "❌ 错误" }, + { key: "WARN", label: "⚠️ 警告" }, + { key: "INFO", label: "ℹ️ 信息" }, + { key: "DEBUG", label: "🅱️ 调试" }, + { key: "ALL", label: "全部" }, + ], + }, ], }); diff --git a/package-lock.json b/package-lock.json index 608d094..57ed10e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "@iringo/geoservices", "license": "Apache-2.0", "dependencies": { - "@nsnanocat/util": "^1.7.5", + "@nsnanocat/util": "^1.7.6", "@protobuf-ts/runtime": "^2.9.3" }, "devDependencies": { @@ -231,9 +231,9 @@ } }, "node_modules/@jsonjoy.com/json-pack": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@jsonjoy.com/json-pack/-/json-pack-1.1.0.tgz", - "integrity": "sha512-zlQONA+msXPPwHWZMKFVS78ewFczIll5lXiVPwFPCZUsrOKdxc2AvxU1HoNBmMRhqDZUR9HkC3UOm+6pME6Xsg==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@jsonjoy.com/json-pack/-/json-pack-1.1.1.tgz", + "integrity": "sha512-osjeBqMJ2lb/j/M8NCPjs1ylqWIcTRTycIhVB5pt6LgzgeRSb0YRZ7j9RfA8wIUrsr/medIuhVyonXRZWLyfdw==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -355,9 +355,9 @@ } }, "node_modules/@nsnanocat/util": { - "version": "1.7.5", - "resolved": "https://registry.npmjs.org/@nsnanocat/util/-/util-1.7.5.tgz", - "integrity": "sha512-9PQFQV4iRMx7y+m2oKBTEc7zE7Ci4cevbHYqlW7mHggSTM2eI2srLlJ8952vfwPt8hEcHS7do7Cx+6QAT0fodA==", + "version": "1.7.6", + "resolved": "https://npm.pkg.github.com/download/@nsnanocat/util/1.7.6/4c7a65d6e991a2bfe1dd19651874bd3b3779d740", + "integrity": "sha512-vttYKFHhpl1O5r6jCXwyQ1n8i6RJ0oMUhTjXV2B6HZI2yucPnxK4ZVlAcM1zxee5+Wm7acGxRZXLGVXg7HV9hA==", "license": "Apache-2.0", "dependencies": { "pako": "^2.1.0" @@ -437,16 +437,16 @@ } }, "node_modules/@puppeteer/browsers": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.5.0.tgz", - "integrity": "sha512-6TQAc/5uRILE6deixJ1CR8rXyTbzXIXNgO1D0Woi9Bqicz2FV5iKP3BHYEg6o4UATCMcbQQ0jbmeaOkn/HQk2w==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.6.0.tgz", + "integrity": "sha512-jESwj3APl78YUWHf28s2EjL0OIxcvl1uLU6Ge68KQ9ZXNsekUcbdr9dCi6vEO8naXS18lWXCV56shVkPStzXSQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "debug": "^4.3.7", + "debug": "^4.4.0", "extract-zip": "^2.0.1", "progress": "^2.0.3", - "proxy-agent": "^6.4.0", + "proxy-agent": "^6.5.0", "semver": "^7.6.3", "tar-fs": "^3.0.6", "unbzip2-stream": "^1.4.3", @@ -1260,43 +1260,15 @@ } }, "node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", + "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", "dev": true, "license": "MIT", - "dependencies": { - "debug": "^4.3.4" - }, "engines": { "node": ">= 14" } }, - "node_modules/agent-base/node_modules/debug": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", - "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", - "dev": true, - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/agent-base/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, - "license": "MIT" - }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -1979,9 +1951,9 @@ } }, "node_modules/call-bind-apply-helpers": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.0.tgz", - "integrity": "sha512-CCKAP2tkPau7D3GE8+V8R6sQubA9R5foIzGp+85EXCVSCivuxBNAWqcpn72PKYiIcqoViv/kcUDpaEIMBVi1lQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz", + "integrity": "sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==", "dev": true, "license": "MIT", "dependencies": { @@ -2727,9 +2699,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.71", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.71.tgz", - "integrity": "sha512-dB68l59BI75W1BUGVTAEJy45CEVuEGy9qPVVQ8pnHyHMn36PLPPoE1mjLH+lo9rKulO3HC2OhbACI/8tCqJBcA==", + "version": "1.5.72", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.72.tgz", + "integrity": "sha512-ZpSAUOZ2Izby7qnZluSrAlGgGQzucmFbN0n64dYzocYxnxV5ufurpj3VgEe4cUp7ir9LmeLxNYo8bVnlM8bQHw==", "dev": true, "license": "ISC", "peer": true @@ -3854,13 +3826,13 @@ "license": "MIT" }, "node_modules/https-proxy-agent": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", - "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", "dev": true, "license": "MIT", "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "4" }, "engines": { @@ -4502,9 +4474,9 @@ } }, "node_modules/memfs": { - "version": "4.14.1", - "resolved": "https://registry.npmjs.org/memfs/-/memfs-4.14.1.tgz", - "integrity": "sha512-Fq5CMEth+2iprLJ5mNizRcWuiwRZYjNkUD0zKk224jZunE9CRacTRDK8QLALbMBlNX2y3nY6lKZbesCwDwacig==", + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/memfs/-/memfs-4.15.0.tgz", + "integrity": "sha512-q9MmZXd2rRWHS6GU3WEm3HyiXZyyoA1DqdOhEq0lxPBmKb5S7IAOwX0RgUCwJfqjelDCySa5h8ujOy24LqsWcw==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -5089,20 +5061,20 @@ } }, "node_modules/pac-proxy-agent": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.2.tgz", - "integrity": "sha512-BFi3vZnO9X5Qt6NRz7ZOaPja3ic0PhlsmCRYLOpN11+mWBCR6XJDqW5RF3j8jm4WGGQZtBA+bTfxYzeKW73eHg==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.1.0.tgz", + "integrity": "sha512-Z5FnLVVZSnX7WjBg0mhDtydeRZ1xMcATZThjySQUHqr+0ksP8kqaw23fNKkaaN/Z8gwLUs/W7xdl0I75eP2Xyw==", "dev": true, "license": "MIT", "dependencies": { "@tootallnate/quickjs-emscripten": "^0.23.0", - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "^4.3.4", "get-uri": "^6.0.1", "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.5", + "https-proxy-agent": "^7.0.6", "pac-resolver": "^7.0.1", - "socks-proxy-agent": "^8.0.4" + "socks-proxy-agent": "^8.0.5" }, "engines": { "node": ">= 14" @@ -5394,20 +5366,20 @@ } }, "node_modules/proxy-agent": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.4.0.tgz", - "integrity": "sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.5.0.tgz", + "integrity": "sha512-TmatMXdr2KlRiA2CyDu8GqR8EjahTG3aY3nXjdzFyoZbmB8hrBsTyMezhULIXKnC0jpfjlmiZ3+EaCzoInSu/A==", "dev": true, "license": "MIT", "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "^4.3.4", "http-proxy-agent": "^7.0.1", - "https-proxy-agent": "^7.0.3", + "https-proxy-agent": "^7.0.6", "lru-cache": "^7.14.1", - "pac-proxy-agent": "^7.0.1", + "pac-proxy-agent": "^7.1.0", "proxy-from-env": "^1.1.0", - "socks-proxy-agent": "^8.0.2" + "socks-proxy-agent": "^8.0.5" }, "engines": { "node": ">= 14" @@ -5486,18 +5458,18 @@ "license": "MIT" }, "node_modules/puppeteer": { - "version": "23.10.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-23.10.1.tgz", - "integrity": "sha512-kbcO+vu91fgUyBzEwByPe4q5lEEuBq4cuOZnZeRL42G7r5UrfbUFlxBJayXBLBsD6pREdk/92ZFwFQq3MaN6ww==", + "version": "23.10.2", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-23.10.2.tgz", + "integrity": "sha512-Iii2ZwdukXzEGeCxs2/GG8G+dbVCylnlBrTxZnMxLW/7w/ftoGq4VB2Bt1vwrbMIn1XwFqxYEWNEkZpIkcVfwg==", "dev": true, "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "@puppeteer/browsers": "2.5.0", + "@puppeteer/browsers": "2.6.0", "chromium-bidi": "0.8.0", "cosmiconfig": "^9.0.0", "devtools-protocol": "0.0.1367902", - "puppeteer-core": "23.10.1", + "puppeteer-core": "23.10.2", "typed-query-selector": "^2.12.0" }, "bin": { @@ -5508,15 +5480,15 @@ } }, "node_modules/puppeteer-core": { - "version": "23.10.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-23.10.1.tgz", - "integrity": "sha512-ey6NwixHYEUnhCA/uYi7uQQ4a0CZw4k+MatbHXGl5GEzaiRQziYUxc2HGpdQZ/gnh4KQWAKkocyIg1/dIm5d0g==", + "version": "23.10.2", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-23.10.2.tgz", + "integrity": "sha512-SEPjEbhPxRlzjGRCs8skwfnzFQj6XrZZmoMz0JIQbanj0fBpQ5HOGgyQTyh4YOW33q+461plJc5GfsQ+ErVBgQ==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@puppeteer/browsers": "2.5.0", + "@puppeteer/browsers": "2.6.0", "chromium-bidi": "0.8.0", - "debug": "^4.3.7", + "debug": "^4.4.0", "devtools-protocol": "0.0.1367902", "typed-query-selector": "^2.12.0", "ws": "^8.18.0" @@ -6279,13 +6251,13 @@ } }, "node_modules/socks-proxy-agent": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.4.tgz", - "integrity": "sha512-GNAq/eg8Udq2x0eNiFkr9gRg5bA7PXEWagQdeRX4cPSG+X/8V38v637gim9bjFptMk1QWsCTr0ttrJEiXbNnRw==", + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", "dev": true, "license": "MIT", "dependencies": { - "agent-base": "^7.1.1", + "agent-base": "^7.1.2", "debug": "^4.3.4", "socks": "^2.8.3" }, diff --git a/package.json b/package.json index ddb833b..d827c22 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "node-polyfill-webpack-plugin": "^4.1.0" }, "dependencies": { - "@nsnanocat/util": "^1.7.5", + "@nsnanocat/util": "^1.7.6", "@protobuf-ts/runtime": "^2.9.3" } } diff --git a/src/class/GEOPDPlaceRequest.mjs b/src/class/GEOPDPlaceRequest.mjs index d7a148c..f0e4895 100644 --- a/src/class/GEOPDPlaceRequest.mjs +++ b/src/class/GEOPDPlaceRequest.mjs @@ -4,35 +4,39 @@ import { PDPlaceRequest, RequestType } from "../proto/apple/geo/GEOPDPlaceReques //import { GeoServiceTag_ServiceType } from "../proto/apple/geo/GEOPDAnalyticMetadata.js"; import { ComponentType } from "../proto/apple/geo/GEOPDComponentInfo.js"; export default class GEOPDPlaceRequest { - static decode(rawBody = new Uint8Array([])) { - Console.log("☑️ GEOPDPlaceRequest.decode"); - const body = PDPlaceRequest.fromBinary(rawBody); - if (typeof body?.analyticMetadata?.serviceTag !== "undefined") body.analyticMetadata.serviceTag.map(serviceTag => { - if (typeof serviceTag.serviceType !== "undefined") serviceTag.serviceType = GeoServiceTag_ServiceType[serviceTag.serviceType]; - return serviceTag; - }); - if (typeof body?.requestedComponents !== "undefined") body.requestedComponents.map(requestedComponent => { - if (typeof requestedComponent.type !== "undefined") requestedComponent.type = ComponentType[requestedComponent.type]; - return requestedComponent; - }); - if (typeof body.requestType !== "undefined") body.requestType = RequestType[body.requestType]; - Console.log("✅ GEOPDPlaceRequest.decode"); - return body; - }; + static decode(rawBody = new Uint8Array([])) { + Console.log("☑️ GEOPDPlaceRequest.decode"); + const body = PDPlaceRequest.fromBinary(rawBody); + if (typeof body?.analyticMetadata?.serviceTag !== "undefined") + body.analyticMetadata.serviceTag.map(serviceTag => { + if (typeof serviceTag.serviceType !== "undefined") serviceTag.serviceType = GeoServiceTag_ServiceType[serviceTag.serviceType]; + return serviceTag; + }); + if (typeof body?.requestedComponents !== "undefined") + body.requestedComponents.map(requestedComponent => { + if (typeof requestedComponent.type !== "undefined") requestedComponent.type = ComponentType[requestedComponent.type]; + return requestedComponent; + }); + if (typeof body.requestType !== "undefined") body.requestType = RequestType[body.requestType]; + Console.log("✅ GEOPDPlaceRequest.decode"); + return body; + } - static encode(body = {}) { - Console.log("☑️ GEOPDPlaceRequest.encode"); - if (typeof body?.analyticMetadata?.serviceTag !== "undefined") body.analyticMetadata.serviceTag.map(serviceTag => { - if (typeof serviceTag.serviceType !== "undefined") serviceTag.serviceType = GeoServiceTag_ServiceType[serviceTag.serviceType]; - return serviceTag; - }); - if (typeof body?.requestedComponents !== "undefined") body.requestedComponents.map(requestedComponent => { - if (typeof requestedComponent.type !== "undefined") requestedComponent.type = ComponentType[requestedComponent.type]; - return requestedComponent; - }); - if (typeof body.requestType !== "undefined") body.requestType = RequestType[body.requestType]; - const rawBody = PDPlaceRequest.toBinary(body); - Console.log("✅ GEOPDPlaceRequest.encode"); - return rawBody; - }; -}; + static encode(body = {}) { + Console.log("☑️ GEOPDPlaceRequest.encode"); + if (typeof body?.analyticMetadata?.serviceTag !== "undefined") + body.analyticMetadata.serviceTag.map(serviceTag => { + if (typeof serviceTag.serviceType !== "undefined") serviceTag.serviceType = GeoServiceTag_ServiceType[serviceTag.serviceType]; + return serviceTag; + }); + if (typeof body?.requestedComponents !== "undefined") + body.requestedComponents.map(requestedComponent => { + if (typeof requestedComponent.type !== "undefined") requestedComponent.type = ComponentType[requestedComponent.type]; + return requestedComponent; + }); + if (typeof body.requestType !== "undefined") body.requestType = RequestType[body.requestType]; + const rawBody = PDPlaceRequest.toBinary(body); + Console.log("✅ GEOPDPlaceRequest.encode"); + return rawBody; + } +} diff --git a/src/class/GEOResourceManifest.mjs b/src/class/GEOResourceManifest.mjs index d8ebbfa..4934e36 100644 --- a/src/class/GEOResourceManifest.mjs +++ b/src/class/GEOResourceManifest.mjs @@ -139,7 +139,7 @@ export default class GEOResourceManifest { case "VECTOR_TRAFFIC_SKELETON_WITH_HISTORICAL": // 28 交通状况骨架(卫星地图:显示历史交通状况)? case "VECTOR_TRAFFIC_V2": // 86 交通状况V2 //Console.warn(`Traffic style: ${tile?.style}`); - /* + /* switch (settings.TileSet.Traffic) { case "HYBRID": default: @@ -319,7 +319,7 @@ export default class GEOResourceManifest { case "VMAP4_ELEVATION_POLAR": // 93 VMAP4 高程(极地)? case "CELLULAR_COVERAGE_PLMN": // 94 蜂窝覆盖 PLMN? case "UNUSED_99": // 99 未使用 - break; + break; default: Console.warn(`default style: ${tile?.style}`); /* diff --git a/src/class/GEOResourceManifestDownload.mjs b/src/class/GEOResourceManifestDownload.mjs index 6172f19..80422ad 100644 --- a/src/class/GEOResourceManifestDownload.mjs +++ b/src/class/GEOResourceManifestDownload.mjs @@ -4,105 +4,121 @@ import { Resources, ResourceType, ResourceFilterScale, ResourceFilterScenario, R import { TileSetStyle, TileScale, TileSize, GenericTileType, TileSet_TileUpdateBehavior, TileSet_ChecksumType, TileSet_RequestStyle } from "../proto/apple/geo/protobuf/geo.js"; export default class GEOResourceManifestDownload { - static decode(rawBody = new Uint8Array([])) { - Console.log("☑️ GEOResourceManifestDownload.decode"); - const body = Resources.fromBinary(rawBody); - //Console.debug(`body.tileSet: ${JSON.stringify(body.tileSet)}`); - if (typeof body.tileSet !== "undefined") body.tileSet = body.tileSet.map((tile) => { - if (typeof tile.style !== "undefined") tile.style = TileSetStyle[tile.style]; - if (typeof tile.validVersion !== "undefined") tile.validVersion = tile.validVersion.map(version => { - if (typeof version.genericTile !== "undefined") version.genericTile = version.genericTile.map(genericTile => { - if (typeof genericTile.tileType !== "undefined") genericTile.tileType = GenericTileType[genericTile.tileType]; - return genericTile; - }); - return version; - }); - if (typeof tile.scale !== "undefined") tile.scale = TileScale[tile.scale]; - if (typeof tile.size !== "undefined") tile.size = TileSize[tile.size]; - if (typeof tile.updateBehavior !== "undefined") tile.updateBehavior = TileSet_TileUpdateBehavior[tile.updateBehavior]; - if (typeof tile.checksumType !== "undefined") tile.checksumType = TileSet_ChecksumType[tile.checksumType]; - if (typeof tile.requestStyle !== "undefined") tile.requestStyle = TileSet_RequestStyle[tile.requestStyle]; - return tile; - }); - if (typeof body.attribution !== "undefined") body.attribution = body.attribution.map(attribution => { - if (typeof attribution.resource !== "undefined") attribution.resource = attribution.resource.map(resource => { - if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; - if (typeof resource.filter !== "undefined") resource.filter = resource.filter.map(filter => { - if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); - if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); - return filter; - }); - if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; - if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; - if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; - return resource; - }); - return attribution; - }); - if (typeof body.resource !== "undefined") body.resource = body.resource.map(resource => { - if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; - if (typeof resource.filter !== "undefined") resource.filter = resource.filter.map(filter => { - if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); - if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); - return filter; - }); - if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; - if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; - if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; - return resource; - }); - Console.log("✅ GEOResourceManifestDownload.decode"); - return body; - }; + static decode(rawBody = new Uint8Array([])) { + Console.log("☑️ GEOResourceManifestDownload.decode"); + const body = Resources.fromBinary(rawBody); + //Console.debug(`body.tileSet: ${JSON.stringify(body.tileSet)}`); + if (typeof body.tileSet !== "undefined") + body.tileSet = body.tileSet.map(tile => { + if (typeof tile.style !== "undefined") tile.style = TileSetStyle[tile.style]; + if (typeof tile.validVersion !== "undefined") + tile.validVersion = tile.validVersion.map(version => { + if (typeof version.genericTile !== "undefined") + version.genericTile = version.genericTile.map(genericTile => { + if (typeof genericTile.tileType !== "undefined") genericTile.tileType = GenericTileType[genericTile.tileType]; + return genericTile; + }); + return version; + }); + if (typeof tile.scale !== "undefined") tile.scale = TileScale[tile.scale]; + if (typeof tile.size !== "undefined") tile.size = TileSize[tile.size]; + if (typeof tile.updateBehavior !== "undefined") tile.updateBehavior = TileSet_TileUpdateBehavior[tile.updateBehavior]; + if (typeof tile.checksumType !== "undefined") tile.checksumType = TileSet_ChecksumType[tile.checksumType]; + if (typeof tile.requestStyle !== "undefined") tile.requestStyle = TileSet_RequestStyle[tile.requestStyle]; + return tile; + }); + if (typeof body.attribution !== "undefined") + body.attribution = body.attribution.map(attribution => { + if (typeof attribution.resource !== "undefined") + attribution.resource = attribution.resource.map(resource => { + if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; + if (typeof resource.filter !== "undefined") + resource.filter = resource.filter.map(filter => { + if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); + if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); + return filter; + }); + if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; + if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; + if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; + return resource; + }); + return attribution; + }); + if (typeof body.resource !== "undefined") + body.resource = body.resource.map(resource => { + if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; + if (typeof resource.filter !== "undefined") + resource.filter = resource.filter.map(filter => { + if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); + if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); + return filter; + }); + if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; + if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; + if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; + return resource; + }); + Console.log("✅ GEOResourceManifestDownload.decode"); + return body; + } - static encode(body = {}) { - Console.log("☑️ GEOResourceManifestDownload.encode"); - if (typeof body.tileSet !== "undefined") body.tileSet = body.tileSet.map((tile) => { - if (typeof tile.style !== "undefined") tile.style = TileSetStyle[tile.style]; - if (typeof tile.validVersion !== "undefined") tile.validVersion = tile.validVersion.map(version => { - if (typeof version.genericTile !== "undefined") version.genericTile = version.genericTile.map(genericTile => { - if (typeof genericTile.tileType !== "undefined") genericTile.tileType = GenericTileType[genericTile.tileType]; - return genericTile; - }); - return version; - }); - if (typeof tile.scale !== "undefined") tile.scale = TileScale[tile.scale]; - if (typeof tile.size !== "undefined") tile.size = TileSize[tile.size]; - if (typeof tile.updateBehavior !== "undefined") tile.updateBehavior = TileSet_TileUpdateBehavior[tile.updateBehavior]; - if (typeof tile.checksumType !== "undefined") tile.checksumType = TileSet_ChecksumType[tile.checksumType]; - if (typeof tile.requestStyle !== "undefined") tile.requestStyle = TileSet_RequestStyle[tile.requestStyle]; - return tile; - }); - if (typeof body.attribution !== "undefined") body.attribution = body.attribution.map(attribution => { - if (typeof attribution.resource !== "undefined") attribution.resource = attribution.resource.map(resource => { - if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; - if (typeof resource.filter !== "undefined") resource.filter = resource.filter.map(filter => { - if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); - if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); - return filter; - }); - if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; - if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; - if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; - return resource; - }); - return attribution; - }); - if (typeof body.resource !== "undefined") body.resource = body.resource.map(resource => { - if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; - if (typeof resource.filter !== "undefined") resource.filter = resource.filter.map(filter => { - if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); - if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); - return filter; - }); - if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; - if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; - if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; - return resource; - }); - //Console.debug(`body.tileSet: ${JSON.stringify(body.tileSet)}`); - const rawBody = Resources.toBinary(body); - Console.log("✅ GEOResourceManifestDownload.encode"); - return rawBody; - }; -}; + static encode(body = {}) { + Console.log("☑️ GEOResourceManifestDownload.encode"); + if (typeof body.tileSet !== "undefined") + body.tileSet = body.tileSet.map(tile => { + if (typeof tile.style !== "undefined") tile.style = TileSetStyle[tile.style]; + if (typeof tile.validVersion !== "undefined") + tile.validVersion = tile.validVersion.map(version => { + if (typeof version.genericTile !== "undefined") + version.genericTile = version.genericTile.map(genericTile => { + if (typeof genericTile.tileType !== "undefined") genericTile.tileType = GenericTileType[genericTile.tileType]; + return genericTile; + }); + return version; + }); + if (typeof tile.scale !== "undefined") tile.scale = TileScale[tile.scale]; + if (typeof tile.size !== "undefined") tile.size = TileSize[tile.size]; + if (typeof tile.updateBehavior !== "undefined") tile.updateBehavior = TileSet_TileUpdateBehavior[tile.updateBehavior]; + if (typeof tile.checksumType !== "undefined") tile.checksumType = TileSet_ChecksumType[tile.checksumType]; + if (typeof tile.requestStyle !== "undefined") tile.requestStyle = TileSet_RequestStyle[tile.requestStyle]; + return tile; + }); + if (typeof body.attribution !== "undefined") + body.attribution = body.attribution.map(attribution => { + if (typeof attribution.resource !== "undefined") + attribution.resource = attribution.resource.map(resource => { + if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; + if (typeof resource.filter !== "undefined") + resource.filter = resource.filter.map(filter => { + if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); + if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); + return filter; + }); + if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; + if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; + if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; + return resource; + }); + return attribution; + }); + if (typeof body.resource !== "undefined") + body.resource = body.resource.map(resource => { + if (typeof resource.resourceType !== "undefined") resource.resourceType = ResourceType[resource.resourceType]; + if (typeof resource.filter !== "undefined") + resource.filter = resource.filter.map(filter => { + if (typeof filter.scale !== "undefined") filter.scale = filter.scale.map(scale => ResourceFilterScale[scale]); + if (typeof filter.scenario !== "undefined") filter.scenario = filter.scenario.map(scenario => ResourceFilterScenario[scenario]); + return filter; + }); + if (typeof resource.connectionType !== "undefined") resource.connectionType = ResourceDownloadConnectionType[resource.connectionType]; + if (typeof resource.validationMethod !== "undefined") resource.validationMethod = Resource_ValidationMethod[resource.validationMethod]; + if (typeof resource.updateMethod !== "undefined") resource.updateMethod = Resource_UpdateMethod[resource.updateMethod]; + return resource; + }); + //Console.debug(`body.tileSet: ${JSON.stringify(body.tileSet)}`); + const rawBody = Resources.toBinary(body); + Console.log("✅ GEOResourceManifestDownload.encode"); + return rawBody; + } +} diff --git a/src/function/database.mjs b/src/function/database.mjs index e972b4f..61f4898 100644 --- a/src/function/database.mjs +++ b/src/function/database.mjs @@ -1,59 +1,248 @@ export default { - "Location": { - "Settings": { - "PEP": { - "GCC": "US" - } - } - }, - "Maps": { - "Settings": { - "UrlInfoSet": { - "Dispatcher": "AutoNavi", - "Directions": "AutoNavi", - "RAP": "Apple", - "LocationShift": "AUTO" - }, - "TileSet": { - "Map": "CN", - "Satellite": "HYBRID", - "Traffic": "CN", - "POI": "CN", - "Flyover": "XX", - "Munin": "XX" - }, - "GeoManifest": { - "Dynamic": { - "Config": { - "CountryCode": "CN" - } - } - }, - "Config": { - "Announcements": { - "Environment:": "CN" - } - } - }, - "Configs": {} - }, - "Watch": { - "Settings": { - "UrlInfoSet": { - "LocationShift": "Apple" - }, - "GeoManifest": { - "Dynamic": { - "Config": { - "CountryCode": "US" - } - } - }, - "Config": { - "Announcements": { - "Environment:": "CN" - } - } - } - } -} + Location: { + Settings: { + PEP: { + GCC: "US", + }, + }, + Configs: {}, + }, + Maps: { + Settings: { + UrlInfoSet: { + Dispatcher: "AutoNavi", + Directions: "AutoNavi", + RAP: "Apple", + LocationShift: "AUTO", + }, + TileSet: { + Map: "CN", + Satellite: "HYBRID", + Traffic: "CN", + POI: "CN", + Flyover: "XX", + Munin: "XX", + }, + GeoManifest: { + Dynamic: { + Config: { + CountryCode: "CN", + }, + }, + }, + Config: { + Announcements: { + "Environment:": "CN", + }, + }, + }, + Configs: {}, + }, + Watch: { + Settings: { + UrlInfoSet: { + LocationShift: "Apple", + }, + GeoManifest: { + Dynamic: { + Config: { + CountryCode: "US", + }, + }, + }, + Config: { + Announcements: { + "Environment:": "CN", + }, + }, + }, + Configs: {}, + }, + Default: { + Settings: { + LogLevel: "WARN", + }, + Configs: { + Storefront: { + AE: "143481", + AF: "143610", + AG: "143540", + AI: "143538", + AL: "143575", + AM: "143524", + AO: "143564", + AR: "143505", + AT: "143445", + AU: "143460", + AZ: "143568", + BA: "143612", + BB: "143541", + BD: "143490", + BE: "143446", + BF: "143578", + BG: "143526", + BH: "143559", + BJ: "143576", + BM: "143542", + BN: "143560", + BO: "143556", + BR: "143503", + BS: "143539", + BT: "143577", + BW: "143525", + BY: "143565", + BZ: "143555", + CA: "143455", + CD: "143613", + CG: "143582", + CH: "143459", + CI: "143527", + CL: "143483", + CM: "143574", + CN: "143465", + CO: "143501", + CR: "143495", + CV: "143580", + CY: "143557", + CZ: "143489", + DE: "143443", + DK: "143458", + DM: "143545", + DO: "143508", + DZ: "143563", + EC: "143509", + EE: "143518", + EG: "143516", + ES: "143454", + FI: "143447", + FJ: "143583", + FM: "143591", + FR: "143442", + GA: "143614", + GB: "143444", + GD: "143546", + GF: "143615", + GH: "143573", + GM: "143584", + GR: "143448", + GT: "143504", + GW: "143585", + GY: "143553", + HK: "143463", + HN: "143510", + HR: "143494", + HU: "143482", + ID: "143476", + IE: "143449", + IL: "143491", + IN: "143467", + IQ: "143617", + IS: "143558", + IT: "143450", + JM: "143511", + JO: "143528", + JP: "143462", + KE: "143529", + KG: "143586", + KH: "143579", + KN: "143548", + KP: "143466", + KR: "143466", + KW: "143493", + KY: "143544", + KZ: "143517", + TC: "143552", + TD: "143581", + TJ: "143603", + TH: "143475", + TM: "143604", + TN: "143536", + TO: "143608", + TR: "143480", + TT: "143551", + TW: "143470", + TZ: "143572", + LA: "143587", + LB: "143497", + LC: "143549", + LI: "143522", + LK: "143486", + LR: "143588", + LT: "143520", + LU: "143451", + LV: "143519", + LY: "143567", + MA: "143620", + MD: "143523", + ME: "143619", + MG: "143531", + MK: "143530", + ML: "143532", + MM: "143570", + MN: "143592", + MO: "143515", + MR: "143590", + MS: "143547", + MT: "143521", + MU: "143533", + MV: "143488", + MW: "143589", + MX: "143468", + MY: "143473", + MZ: "143593", + NA: "143594", + NE: "143534", + NG: "143561", + NI: "143512", + NL: "143452", + NO: "143457", + NP: "143484", + NR: "143606", + NZ: "143461", + OM: "143562", + PA: "143485", + PE: "143507", + PG: "143597", + PH: "143474", + PK: "143477", + PL: "143478", + PT: "143453", + PW: "143595", + PY: "143513", + QA: "143498", + RO: "143487", + RS: "143500", + RU: "143469", + RW: "143621", + SA: "143479", + SB: "143601", + SC: "143599", + SE: "143456", + SG: "143464", + SI: "143499", + SK: "143496", + SL: "143600", + SN: "143535", + SR: "143554", + ST: "143598", + SV: "143506", + SZ: "143602", + UA: "143492", + UG: "143537", + US: "143441", + UY: "143514", + UZ: "143566", + VC: "143550", + VE: "143502", + VG: "143543", + VN: "143471", + VU: "143609", + XK: "143624", + YE: "143571", + ZA: "143472", + ZM: "143622", + ZW: "143605", + }, + }, + }, +}; diff --git a/src/function/setENV.mjs b/src/function/setENV.mjs index 8b49ca7..c625d62 100644 --- a/src/function/setENV.mjs +++ b/src/function/setENV.mjs @@ -12,7 +12,7 @@ export default function setENV(name, platforms, database) { Console.log("☑️ Set Environment Variables"); const { Settings, Caches, Configs } = getStorage(name, platforms, database); /***************** Settings *****************/ - Console.debug(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`); + Console.info(`typeof Settings: ${typeof Settings}`, `Settings: ${JSON.stringify(Settings, null, 2)}`); /***************** Caches *****************/ //Console.debug(`typeof Caches: ${typeof Caches}`, `Caches: ${JSON.stringify(Caches)}`); /***************** Configs *****************/ @@ -21,4 +21,4 @@ export default function setENV(name, platforms, database) { if (Configs.i18n) for (const type in Configs.i18n) Configs.i18n[type] = new Map(Configs.i18n[type]); Console.log("✅ Set Environment Variables"); return { Settings, Caches, Configs }; -}; +} diff --git a/src/request.dev.js b/src/request.dev.js index 7e911db..9b4ff6d 100644 --- a/src/request.dev.js +++ b/src/request.dev.js @@ -10,26 +10,25 @@ let $response = undefined; const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); const PLATFORM = ["Maps"]; if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch"); Console.info(`PLATFORM: ${PLATFORM}`); -!(async () => { +(async () => { /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 方法判断 - switch (METHOD) { + switch ($request.method) { case "POST": case "PUT": case "PATCH": @@ -82,10 +81,10 @@ Console.info(`PLATFORM: ${PLATFORM}`); //Console.debug(`$request: ${JSON.stringify($request, null, 2)}`); let rawBody = $app === "Quantumult X" ? new Uint8Array($request.bodyBytes ?? []) : ($request.body ?? new Uint8Array()); //Console.debug(`isBuffer? ${ArrayBuffer.isView(rawBody)}: ${JSON.stringify(rawBody, null, 2)}`); - switch (HOST) { + switch (url.hostname) { case "gsp-ssl.ls.apple.com": case "dispatcher.is.autonavi.com": - switch (PATH) { + switch (url.pathname) { case "/dispatcher.arpc": case "/dispatcher": { /****************** initialization start *******************/ @@ -127,16 +126,16 @@ Console.info(`PLATFORM: ${PLATFORM}`); delete $request?.headers?.["If-None-Match"]; delete $request?.headers?.["if-none-match"]; // 主机判断 - switch (HOST) { + switch (url.hostname) { case "configuration.ls.apple.com": // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": break; } break; case "gspe1-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": /* // 不使用 echo response $response = { @@ -156,7 +155,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); break; case "gspe35-ssl.ls.apple.com": case "gspe35-ssl.ls.apple.cn": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": switch (Settings?.Config?.Announcements?.Environment) { case "AUTO": diff --git a/src/request.js b/src/request.js index 7a30f19..3c19716 100644 --- a/src/request.js +++ b/src/request.js @@ -9,26 +9,25 @@ let $response = undefined; const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($request.headers?.["Content-Type"] ?? $request.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); const PLATFORM = ["Maps"]; if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch"); Console.info(`PLATFORM: ${PLATFORM}`); -!(async () => { +(async () => { /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 方法判断 - switch (METHOD) { + switch ($request.method) { case "POST": case "PUT": case "PATCH": @@ -94,16 +93,16 @@ Console.info(`PLATFORM: ${PLATFORM}`); delete $request?.headers?.["If-None-Match"]; delete $request?.headers?.["if-none-match"]; // 主机判断 - switch (HOST) { + switch (url.hostname) { case "configuration.ls.apple.com": // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": break; } break; case "gspe1-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": /* // 不使用 echo response $response = { @@ -123,7 +122,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); break; case "gspe35-ssl.ls.apple.com": case "gspe35-ssl.ls.apple.cn": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": switch (Settings?.Config?.Announcements?.Environment) { case "AUTO": diff --git a/src/response.dev.js b/src/response.dev.js index 0d08a5e..8f5c18c 100644 --- a/src/response.dev.js +++ b/src/response.dev.js @@ -10,22 +10,21 @@ import { BinaryReader, UnknownFieldHandler } from "@protobuf-ts/runtime"; const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); const PLATFORM = ["Location", "Maps"]; if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch"); Console.info(`PLATFORM: ${PLATFORM}`); -!(async () => { +(async () => { /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 格式判断 @@ -52,11 +51,11 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/plist": case "application/x-plist": // 主机判断 - switch (HOST) { + switch (url.hostname) { case "gspe1-ssl.ls.apple.com": //body = new DOMParser().parseFromString($response.body, FORMAT); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": _.set(Caches, "pep.gcc", $response.body); Storage.setItem("@iRingo.Location.Caches", Caches); @@ -79,7 +78,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); body = XML.parse($response.body); Console.debug(`body: ${JSON.stringify(body)}`); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": { const PLIST = body.plist; if (PLIST) { @@ -144,9 +143,9 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/x-protobuf": case "application/vnd.google.protobuf": case "application/octet-stream": - switch (HOST) { + switch (url.hostname) { case "gspe35-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": break; case "/geo_manifest/dynamic/config": { diff --git a/src/response.js b/src/response.js index ba7c2a0..f522802 100644 --- a/src/response.js +++ b/src/response.js @@ -9,22 +9,21 @@ import GEOResourceManifestDownload from "./class/GEOResourceManifestDownload.mjs const url = new URL($request.url); Console.info(`url: ${url.toJSON()}`); // 获取连接参数 -const METHOD = $request.method, - HOST = url.hostname, - PATH = url.pathname; -Console.info(`METHOD: ${METHOD}, HOST: ${HOST}, PATH: ${PATH}`); +const PATHs = url.pathname.split("/").filter(Boolean); +Console.info(`PATHs: ${PATHs}`); // 解析格式 const FORMAT = ($response.headers?.["Content-Type"] ?? $response.headers?.["content-type"])?.split(";")?.[0]; Console.info(`FORMAT: ${FORMAT}`); const PLATFORM = ["Location", "Maps"]; if (url.searchParams.get("os") === "watchos") PLATFORM.push("Watch"); Console.info(`PLATFORM: ${PLATFORM}`); -!(async () => { +(async () => { /** * 设置 * @type {{Settings: import('./types').Settings}} */ const { Settings, Caches, Configs } = setENV("iRingo", PLATFORM, database); + Console.logLevel = Settings.LogLevel; // 创建空数据 let body = {}; // 格式判断 @@ -47,11 +46,11 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/plist": case "application/x-plist": // 主机判断 - switch (HOST) { + switch (url.hostname) { case "gspe1-ssl.ls.apple.com": //body = new DOMParser().parseFromString($response.body, FORMAT); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/pep/gcc": _.set(Caches, "pep.gcc", $response.body); Storage.setItem("@iRingo.Location.Caches", Caches); @@ -71,7 +70,7 @@ Console.info(`PLATFORM: ${PLATFORM}`); }; body = XML.parse($response.body); // 路径判断 - switch (PATH) { + switch (url.pathname) { case "/config/defaults": { const PLIST = body.plist; if (PLIST) { @@ -129,9 +128,9 @@ Console.info(`PLATFORM: ${PLATFORM}`); case "application/x-protobuf": case "application/vnd.google.protobuf": case "application/octet-stream": - switch (HOST) { + switch (url.hostname) { case "gspe35-ssl.ls.apple.com": - switch (PATH) { + switch (url.pathname) { case "/config/announcements": break; case "/geo_manifest/dynamic/config": { diff --git a/src/types.d.ts b/src/types.d.ts index c70a513..bf1f0dc 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -139,4 +139,22 @@ export interface Settings { */ Munin?: 'AUTO' | 'CN' | 'XX'; }; + /** + * [调试] 日志等级 + * + * 选择脚本日志的输出等级,低于所选等级的日志将全部输出。 + * + * @remarks + * + * Possible values: + * - `'OFF'` - 关闭 + * - `'ERROR'` - ❌ 错误 + * - `'WARN'` - ⚠️ 警告 + * - `'INFO'` - ℹ️ 信息 + * - `'DEBUG'` - 🅱️ 调试 + * - `'ALL'` - 全部 + * + * @defaultValue "WARN" + */ + LogLevel?: 'OFF' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG' | 'ALL'; } diff --git a/template/boxjs.settings.json b/template/boxjs.settings.json index 3ae9888..919d4fc 100644 --- a/template/boxjs.settings.json +++ b/template/boxjs.settings.json @@ -1 +1 @@ -[{"id":"@iRingo.Maps.Settings.GeoManifest.Dynamic.Config.CountryCode","name":"[动态配置] 资源清单的国家或地区代码","type":"selects","val":"CN","items":[{"key":"AUTO","label":"🇺🇳自动(跟随用户当前所在地区)"},{"key":"CN","label":"🇨🇳中国大陆"},{"key":"HK","label":"🇭🇰中国香港"},{"key":"TW","label":"🇹🇼中国台湾"},{"key":"SG","label":"🇸🇬新加坡"},{"key":"US","label":"🇺🇸美国"},{"key":"JP","label":"🇯🇵日本"},{"key":"AU","label":"🇦🇺澳大利亚"},{"key":"GB","label":"🇬🇧英国"},{"key":"KR","label":"🇰🇷韩国"},{"key":"CA","label":"🇨🇦加拿大"},{"key":"IE","label":"🇮🇪爱尔兰"}],"desc":"此选项影响“地图”整体配置内容,包括以下的地图功能与服务。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.Dispatcher","name":"[URL信息集] 调度器","type":"selects","val":"AutoNavi","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:互动百科/大众点评/携程 | 🇺🇳:维基百科/Yelp/Booking)"},{"key":"Apple","label":"Apple(维基百科/Yelp/Booking)"}],"desc":"地点数据接口,此选项影响公共指南,兴趣点(POI)与位置信息等功能。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.Directions","name":"[URL信息集] 导航与ETA","type":"selects","val":"AutoNavi","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:高德地图 | 🇺🇳:TomTom)"},{"key":"Apple","label":"Apple(🇨🇳:🈚️ | 🇺🇳:TomTom)"}],"desc":"导航与ETA服务接口,此选项影响导航与ETA(到达时间)等功能。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.RAP","name":"[URL信息集] 评分和照片","type":"selects","val":"Apple","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:🈶️但未开放 | 🇺🇳:🈚️)"},{"key":"Apple","label":"Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"评分和照片服务接口,此选项影响评分和照片服务以及照片使用。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.LocationShift","name":"[URL信息集] 定位漂移","type":"selects","val":"AUTO","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🈚️坐标,使用🇨🇳GCJ-02坐标)"},{"key":"Apple","label":"Apple(🈶️坐标,使用🇺🇳WGS-84坐标)"}],"desc":"定位漂移修正服务接口,控制定位漂移和🧭指南针与📍坐标的经纬度。"},{"id":"@iRingo.Maps.Settings.TileSet.Satellite","name":"[瓦片数据集] 卫星图像","type":"selects","val":"HYBRID","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"HYBRID","label":"混合(🇨🇳:2D较新 | 🇺🇳:主要城市3D)"},{"key":"CN","label":"🇨🇳中国四维(🇨🇳:2D较新 | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳DigitalGlobe(🇨🇳:2D较旧 | 🇺🇳:2D+主要城市3D)"}],"desc":"此选项影响所列位图、影像与模型数据。"},{"id":"@iRingo.Maps.Settings.TileSet.Flyover","name":"[瓦片数据集] 飞行俯瞰","type":"selects","val":"XX","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"CN","label":"🇨🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"此选项影响飞行俯瞰全球各地的主要地标和城市功能。"},{"id":"@iRingo.Maps.Settings.TileSet.Munin","name":"[瓦片数据集] 四处看看","type":"selects","val":"XX","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"CN","label":"🇨🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"此选项影响 360 度全景视角在某些地点四处看看功能。"}] \ No newline at end of file +[{"id":"@iRingo.Maps.Settings.GeoManifest.Dynamic.Config.CountryCode","name":"[动态配置] 资源清单的国家或地区代码","type":"selects","val":"CN","items":[{"key":"AUTO","label":"🇺🇳自动(跟随用户当前所在地区)"},{"key":"CN","label":"🇨🇳中国大陆"},{"key":"HK","label":"🇭🇰中国香港"},{"key":"TW","label":"🇹🇼中国台湾"},{"key":"SG","label":"🇸🇬新加坡"},{"key":"US","label":"🇺🇸美国"},{"key":"JP","label":"🇯🇵日本"},{"key":"AU","label":"🇦🇺澳大利亚"},{"key":"GB","label":"🇬🇧英国"},{"key":"KR","label":"🇰🇷韩国"},{"key":"CA","label":"🇨🇦加拿大"},{"key":"IE","label":"🇮🇪爱尔兰"}],"desc":"此选项影响“地图”整体配置内容,包括以下的地图功能与服务。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.Dispatcher","name":"[URL信息集] 调度器","type":"selects","val":"AutoNavi","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:互动百科/大众点评/携程 | 🇺🇳:维基百科/Yelp/Booking)"},{"key":"Apple","label":"Apple(维基百科/Yelp/Booking)"}],"desc":"地点数据接口,此选项影响公共指南,兴趣点(POI)与位置信息等功能。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.Directions","name":"[URL信息集] 导航与ETA","type":"selects","val":"AutoNavi","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:高德地图 | 🇺🇳:TomTom)"},{"key":"Apple","label":"Apple(🇨🇳:🈚️ | 🇺🇳:TomTom)"}],"desc":"导航与ETA服务接口,此选项影响导航与ETA(到达时间)等功能。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.RAP","name":"[URL信息集] 评分和照片","type":"selects","val":"Apple","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🇨🇳:🈶️但未开放 | 🇺🇳:🈚️)"},{"key":"Apple","label":"Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"评分和照片服务接口,此选项影响评分和照片服务以及照片使用。"},{"id":"@iRingo.Maps.Settings.UrlInfoSet.LocationShift","name":"[URL信息集] 定位漂移","type":"selects","val":"AUTO","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"AutoNavi","label":"🧭高德(🈚️坐标,使用🇨🇳GCJ-02坐标)"},{"key":"Apple","label":"Apple(🈶️坐标,使用🇺🇳WGS-84坐标)"}],"desc":"定位漂移修正服务接口,控制定位漂移和🧭指南针与📍坐标的经纬度。"},{"id":"@iRingo.Maps.Settings.TileSet.Satellite","name":"[瓦片数据集] 卫星图像","type":"selects","val":"HYBRID","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"HYBRID","label":"混合(🇨🇳:2D较新 | 🇺🇳:主要城市3D)"},{"key":"CN","label":"🇨🇳中国四维(🇨🇳:2D较新 | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳DigitalGlobe(🇨🇳:2D较旧 | 🇺🇳:2D+主要城市3D)"}],"desc":"此选项影响所列位图、影像与模型数据。"},{"id":"@iRingo.Maps.Settings.TileSet.Flyover","name":"[瓦片数据集] 飞行俯瞰","type":"selects","val":"XX","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"CN","label":"🇨🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"此选项影响飞行俯瞰全球各地的主要地标和城市功能。"},{"id":"@iRingo.Maps.Settings.TileSet.Munin","name":"[瓦片数据集] 四处看看","type":"selects","val":"XX","items":[{"key":"AUTO","label":"🇺🇳自动(随[动态配置]版本自动选择)"},{"key":"CN","label":"🇨🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈚️)"},{"key":"XX","label":"🇺🇳Apple(🇨🇳:🈚️ | 🇺🇳:🈶️)"}],"desc":"此选项影响 360 度全景视角在某些地点四处看看功能。"},{"id":"@iRingo.Maps.Settings.LogLevel","name":"[调试] 日志等级","type":"selects","val":"WARN","items":[{"key":"OFF","label":"关闭"},{"key":"ERROR","label":"❌ 错误"},{"key":"WARN","label":"⚠️ 警告"},{"key":"INFO","label":"ℹ️ 信息"},{"key":"DEBUG","label":"🅱️ 调试"},{"key":"ALL","label":"全部"}],"desc":"选择脚本日志的输出等级,低于所选等级的日志将全部输出。"}] \ No newline at end of file