fix: resolve file library Open File bug, upload reliability, and SSE proxy timeouts (#203)

The Open File button in the Files section did nothing due to a race
condition where the home page reset the file store on mount before files
from handleOpenFile could render. Upload on the files page used fetch
with no timeout, progress, or retry, causing silent failures on mobile
and slow connections. SSE connections for job progress had no keepalive
pings, allowing reverse proxies to kill idle streams.
This commit is contained in:
SnapOtter
2026-06-05 19:01:40 +08:00
committed by GitHub
parent f1aae73397
commit 01421640b5
9 changed files with 176 additions and 44 deletions
+14
View File
@@ -237,11 +237,22 @@ export async function registerProgressRoutes(app: FastifyInstance): Promise<void
reply.raw.write(`data: ${JSON.stringify(data)}\n\n`);
};
// Send keepalive comments every 20s to prevent reverse proxies
// (Caddy, Nginx, ALBs) from killing idle SSE connections.
const keepaliveInterval = setInterval(() => {
try {
reply.raw.write(": keepalive\n\n");
} catch {
clearInterval(keepaliveInterval);
}
}, 20_000);
// If the job already has progress, send it immediately
const existing = jobProgressStore.get(jobId);
if (existing) {
sendEvent({ ...existing, type: "batch" });
if (existing.status === "completed" || existing.status === "failed") {
clearInterval(keepaliveInterval);
reply.raw.end();
return;
}
@@ -250,6 +261,7 @@ export async function registerProgressRoutes(app: FastifyInstance): Promise<void
const existingSingle = singleFileCompletions.get(jobId);
if (existingSingle) {
sendEvent(existingSingle);
clearInterval(keepaliveInterval);
reply.raw.end();
return;
}
@@ -268,6 +280,7 @@ export async function registerProgressRoutes(app: FastifyInstance): Promise<void
("phase" in data && (data.phase === "complete" || data.phase === "failed"))
) {
ended = true;
clearInterval(keepaliveInterval);
const subs = listeners.get(jobId);
if (subs) {
subs.delete(callback);
@@ -281,6 +294,7 @@ export async function registerProgressRoutes(app: FastifyInstance): Promise<void
// Clean up on client disconnect
request.raw.on("close", () => {
clearInterval(keepaliveInterval);
const subs = listeners.get(jobId);
if (subs) {
subs.delete(callback);