From 8e1487409d3322bf420ccd0929946bc3faf8dfb6 Mon Sep 17 00:00:00 2001 From: huangxd- <649924757@qq.com> Date: Thu, 19 Mar 2026 22:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9ios=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8BWebAssembly=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=EF=BC=8C=E9=80=82=E9=85=8Dpeekpili=E6=90=AD?= =?UTF-8?q?=E5=BB=BA=E6=9C=AC=E5=9C=B0=E6=9C=8D=E5=8A=A1=20(#245)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- danmu_api/configs/globals.js | 2 +- danmu_api/utils/http-util.js | 80 ++++++++++++++++++++++++++---------- package.json | 1 + 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index c2a0307..90c7b9c 100644 --- a/README.md +++ b/README.md @@ -310,7 +310,7 @@ LogVar 弹幕 API 服务器 > cf部署可能不稳定,推荐用vercel/netlify部署。 ## API食用指南 -支持 forward/senplayer/hills/小幻/yamby/eplayerx/afusekt/uz影视/dscloud/lenna/danmaku-anywhere/omnibox/ChaiChaiEmbyTV/moontv/capyplayer/kerkerker/LinPlayer 等支持弹幕API的播放器。 +支持 forward/senplayer/hills/小幻/yamby/eplayerx/afusekt/uz影视/dscloud/lenna/danmaku-anywhere/omnibox/ChaiChaiEmbyTV/moontv/capyplayer/kerkerker/LinPlayer/peekpili 等支持弹幕API的播放器。 配合 dd-danmaku 扩展新增对 Emby Web 端弹幕的支持,具体使用方法参考 [PR #98](https://github.com/huangxd-/danmu_api/pull/98) 。 diff --git a/danmu_api/configs/globals.js b/danmu_api/configs/globals.js index 84b73c7..1110576 100644 --- a/danmu_api/configs/globals.js +++ b/danmu_api/configs/globals.js @@ -13,7 +13,7 @@ export const Globals = { accessedEnvVars: {}, // 静态常量 - VERSION: '1.17.2', + VERSION: '1.17.3', MAX_LOGS: 1000, // 日志存储,最多保存 1000 行 MAX_ANIMES: 100, MAX_RECORDS: 100, // 请求记录最大数量 diff --git a/danmu_api/utils/http-util.js b/danmu_api/utils/http-util.js index dd13325..6027837 100644 --- a/danmu_api/utils/http-util.js +++ b/danmu_api/utils/http-util.js @@ -46,13 +46,28 @@ export async function httpGet(url, options = {}) { linkSignal(options.signal, controller); try { - const response = await fetch(url, { - method: 'GET', - headers: { - ...options.headers, - }, - signal: controller.signal - }); + // 兼容iOS巨魔环境:使用node-fetch替代内置fetch + let response; + if (typeof WebAssembly === 'undefined') { + log("info", "iOS环境降级使用node-fetch"); + const fetch = (await import('node-fetch')).default; + response = await fetch(url, { + method: 'GET', + headers: { + ...options.headers, + }, + signal: controller.signal + }); + } else { + // 现代浏览器环境 + response = await fetch(url, { + method: 'GET', + headers: { + ...options.headers, + }, + signal: controller.signal + }); + } clearTimeout(timeoutId); @@ -84,20 +99,34 @@ export async function httpGet(url, options = {}) { // 获取 ArrayBuffer const arrayBuffer = await response.arrayBuffer(); - // 使用 DecompressionStream 进行解压 - // "deflate" 对应 zlib 的 inflate - const decompressionStream = new DecompressionStream("deflate"); - const decompressedStream = new Response( - new Blob([arrayBuffer]).stream().pipeThrough(decompressionStream) - ); - - // 读取解压后的文本 + // 兼容iOS巨魔环境:检查DecompressionStream是否可用 let decodedData; - try { - decodedData = await decompressedStream.text(); - } catch (e) { - log("error", "[请求模拟] 解压缩失败", e); - throw e; + if (typeof DecompressionStream !== 'undefined') { + // 现代浏览器环境 + const decompressionStream = new DecompressionStream("deflate"); + const decompressedStream = new Response( + new Blob([arrayBuffer]).stream().pipeThrough(decompressionStream) + ); + try { + decodedData = await decompressedStream.text(); + } catch (e) { + log("error", "[请求模拟] 解压缩失败", e); + throw e; + } + } else { + // iOS巨魔环境降级处理:使用pako库 + log("info", "iOS环境降级使用pako解压"); + try { + // 动态导入pako库 + const pako = await import('pako'); + // 解压数据 + const inflateResult = pako.inflate(new Uint8Array(arrayBuffer)); + // 转换为字符串 + decodedData = new TextDecoder('utf-8').decode(inflateResult); + } catch (e) { + log("error", "[请求模拟] pako解压缩失败", e); + throw e; + } } data = decodedData; // 更新解压后的数据 @@ -223,7 +252,16 @@ export async function httpPost(url, body, options = {}) { } try { - const response = await fetch(url, fetchOptions); + // 兼容iOS巨魔环境:使用node-fetch替代内置fetch + let response; + if (typeof WebAssembly === 'undefined') { + log("info", "iOS环境降级使用node-fetch"); + const fetch = (await import('node-fetch')).default; + response = await fetch(url, fetchOptions); + } else { + // 现代浏览器环境 + response = await fetch(url, fetchOptions); + } clearTimeout(timeoutId); diff --git a/package.json b/package.json index 03dd2a2..44b11fc 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "esbuild": "^0.25.10", "https-proxy-agent": "^7.0.6", "node-fetch": "^3.3.2", + "pako": "^2.1.0", "redis": "^5.11.0" } }