dsh-folia 4.20.1 → 4.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/download-queue.js +5 -0
- package/lib/routes/skins.js +8 -1
- package/package.json +1 -1
package/lib/download-queue.js
CHANGED
|
@@ -100,6 +100,11 @@ export function createDownloadQueue(opts = {}) {
|
|
|
100
100
|
const job = jobs.get(id);
|
|
101
101
|
// 已完成但文件被删 ⇒ 重新排队
|
|
102
102
|
if (job.status === 'done' && !existsSync(job.dest)) { job.status = 'queued'; job.received = 0; }
|
|
103
|
+
// ⚠️ **必须再 pump 一次**:老实现"存在就直接返回",于是一个已经 queued 的 job
|
|
104
|
+
// 如果当时没有在跑的 pump(例如上一条刚结束、或快照被重置成 queued),
|
|
105
|
+
// 就永远没人来启动它 ⇒ 调用方(皮肤安装)会一直等到超时。实测就是这样卡了 5 分钟。
|
|
106
|
+
persist();
|
|
107
|
+
pump();
|
|
103
108
|
return { job: snapshot().find((x) => x.id === id), existed: true };
|
|
104
109
|
}
|
|
105
110
|
jobs.set(id, {
|
package/lib/routes/skins.js
CHANGED
|
@@ -614,7 +614,9 @@ export function registerSkinsRoutes(webServer, c) {
|
|
|
614
614
|
const q = getDownloadQueue();
|
|
615
615
|
const added = q.add({ url: url.toString(), dest: zipDest, kind: 'skin' });
|
|
616
616
|
const jobId = added && added.job ? added.job.id : null;
|
|
617
|
-
|
|
617
|
+
// 上限 120 秒:宁可给用户一个明确的"超时/失败"答复,也不要让他对着界面等 10 分钟
|
|
618
|
+
// (实测过"点了没反应":就是因为这里给了 10 分钟,而队列里的 job 没被 pump 起来)。
|
|
619
|
+
const deadline = Date.now() + 120 * 1000;
|
|
618
620
|
let state = added && added.job ? added.job : null;
|
|
619
621
|
while (Date.now() < deadline) {
|
|
620
622
|
state = q.snapshot().find((j) => j.id === jobId) || state;
|
|
@@ -627,6 +629,11 @@ export function registerSkinsRoutes(webServer, c) {
|
|
|
627
629
|
}
|
|
628
630
|
const total = Number(state && state.total) || 0;
|
|
629
631
|
if (total && total > MAX_ZIP_BYTES) { sendJson(res, 413, { ok: false, error: 'too-large' }); return; }
|
|
632
|
+
// 超时/状态不对:**明确失败**,别让调用方以为"装好了"
|
|
633
|
+
if (!state || state.status !== 'done' || !existsSync(zipDest)) {
|
|
634
|
+
sendJson(res, 504, { ok: false, error: 'download-timeout', detail: (state && state.status) || 'unknown' });
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
630
637
|
buf = readFileSync(zipDest);
|
|
631
638
|
if (buf.length > MAX_ZIP_BYTES) { sendJson(res, 413, { ok: false, error: 'too-large' }); return; }
|
|
632
639
|
} catch (e) {
|