mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-28 07:24:12 +00:00
feat: 优化 Android Node 兼容性和错误日志
This commit is contained in:
6 files changed
+78
-13
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.36.19",
|
||||
"version": "2.36.20",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
|
||||
"main": "src/main.js",
|
||||
"packageManager": "pnpm@11.0.9",
|
||||
|
||||
@@ -22,5 +22,21 @@ console.log(
|
||||
import migrate from '@/utils/migration';
|
||||
import serve from '@/restful';
|
||||
|
||||
if ($.env.isNode) {
|
||||
if (typeof Promise.withResolvers !== 'function') {
|
||||
eval("require('core-js/actual/promise/with-resolvers')");
|
||||
}
|
||||
|
||||
const workerThreads = eval("require('node:worker_threads')");
|
||||
if (typeof workerThreads.markAsUncloneable !== 'function') {
|
||||
// ponytail: Node < 22 cannot mark web objects uncloneable; remove this fallback when the Android runtime reaches Node 22.
|
||||
workerThreads.markAsUncloneable = () => {};
|
||||
}
|
||||
|
||||
eval('process').on('uncaughtExceptionMonitor', (error, origin) => {
|
||||
console.error(`[FATAL] ${origin}: ${error?.stack ?? error}`);
|
||||
});
|
||||
}
|
||||
|
||||
migrate();
|
||||
serve();
|
||||
@@ -208,6 +208,27 @@ describe('download github proxy regex', function () {
|
||||
expect(maxActiveRequests).to.equal(1);
|
||||
});
|
||||
|
||||
it('logs download failures before rejecting', async function () {
|
||||
openApi.HTTP = () => ({
|
||||
get: async () => {
|
||||
throw new Error('request setup failed');
|
||||
},
|
||||
});
|
||||
|
||||
let error;
|
||||
try {
|
||||
await download('https://example.com/failing.txt');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).to.be.instanceOf(Error);
|
||||
expect(error.message).to.equal(
|
||||
'无法下载 URL https://example.com/failing.txt: request setup failed',
|
||||
);
|
||||
expect(errorLogs).to.deep.equal([error.message]);
|
||||
});
|
||||
|
||||
it('returns unpreprocessed raw content when requested', async function () {
|
||||
responseBody = [
|
||||
'proxies:',
|
||||
|
||||
+25
@@ -132,6 +132,31 @@ describe('open-api HTTP adapter', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects request setup errors', async function () {
|
||||
let timeoutCalls = 0;
|
||||
const options = {
|
||||
url: 'https://example.com/subscription',
|
||||
timeout: 5,
|
||||
events: {
|
||||
onTimeout() {
|
||||
timeoutCalls += 1;
|
||||
},
|
||||
},
|
||||
};
|
||||
options.circular = options;
|
||||
|
||||
let error;
|
||||
try {
|
||||
await HTTP().get(options);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
expect(error).to.be.instanceOf(TypeError);
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
expect(timeoutCalls).to.equal(0);
|
||||
});
|
||||
|
||||
it('normalizes Node.js request header names to lowercase', async function () {
|
||||
await HTTP({
|
||||
headers: {
|
||||
|
||||
@@ -484,7 +484,9 @@ export default async function download(
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new Error(`无法下载 URL ${safeUrl}: ${e.message ?? e}`);
|
||||
const message = `无法下载 URL ${safeUrl}: ${e.message ?? e}`;
|
||||
$.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+12
-11
@@ -467,7 +467,7 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
||||
opts: options.opts,
|
||||
});
|
||||
} else if (isLoon || isSurge || isNode) {
|
||||
worker = new Promise(async (resolve, reject) => {
|
||||
const run = async (resolve, reject) => {
|
||||
const body = options.body;
|
||||
const opts = JSON.parse(JSON.stringify(options));
|
||||
opts.body = body;
|
||||
@@ -627,6 +627,9 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
||||
},
|
||||
);
|
||||
}
|
||||
};
|
||||
worker = new Promise((resolve, reject) => {
|
||||
run(resolve, reject).catch(reject);
|
||||
});
|
||||
} else if (isGUIforCores) {
|
||||
worker = new Promise(async (resolve, reject) => {
|
||||
@@ -669,16 +672,14 @@ export function HTTP(defaultOptions = { baseURL: '' }) {
|
||||
})
|
||||
: null;
|
||||
|
||||
return (
|
||||
timer
|
||||
? Promise.race([timer, worker]).then((res) => {
|
||||
if (typeof clearTimeout !== 'undefined') {
|
||||
clearTimeout(timeoutid);
|
||||
}
|
||||
return res;
|
||||
})
|
||||
: worker
|
||||
).then((resp) => events.onResponse(resp));
|
||||
const request = timer ? Promise.race([timer, worker]) : worker;
|
||||
return request
|
||||
.finally(() => {
|
||||
if (timer && typeof clearTimeout !== 'undefined') {
|
||||
clearTimeout(timeoutid);
|
||||
}
|
||||
})
|
||||
.then((resp) => events.onResponse(resp));
|
||||
}
|
||||
|
||||
const http = {
|
||||
|
||||
Reference in new issue
Block a user