兼容ios环境下WebAssembly不存在的场景,适配peekpili搭建本地服务 (#245)
This commit is contained in:
1 parent
7cff1c991b
commit
8e1487409d
4 files changed
+62
-23
No files matched your search
@@ -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) 。
|
||||
|
||||
|
||||
@@ -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, // 请求记录最大数量
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user