Adjust encoded paths so filenames resolve as a basename properly when downloading with things like wget.

This commit is contained in:
Jaret Burkett
2026-08-15 08:56:55 -06:00
parent 151ad0e959
commit e6cffbc002
15 changed files with 94 additions and 39 deletions

View File

@@ -248,6 +248,13 @@ async function serveFile(req: http.IncomingMessage, res: http.ServerResponse, pr
const isImg = prefix === '/api/img/';
const urlPath = (req.url || '').split('?')[0];
const rest = urlPath.slice(prefix.length);
// Decode per URL segment so both forms resolve to the same file:
// /api/files/%2Fmnt%2Fout%2Fjob%2Ffile.safetensors (legacy: whole path in one segment)
// /api/files/%2Fmnt%2Fout%2Fjob/file.safetensors (folder / filename — what the UI emits;
// gives wget & co. the real filename)
// Windows folders arrive as `C%3A%5Cout%5Cjob` and decode to `C:\out\job`;
// path.resolve below normalizes the mixed `\`/`/` separators. Same logic as
// catchAllToFilePath in src/server/catchAllPath.ts for the Next.js routes.
const decodedFilePath = rest
.split('/')
.map(decodeURIComponent)