fix: wrong error code in case upload-temp-hash requires a missing file (500 instead of 404)

Massimo Melina committed Jan 18, 2026 at 00:07 UTC 2be830aa13227934584a0f1970c5dc9fb3e66cbe
2 files changed +3 -1
src/serveGuiAndSharedFiles.ts
+2 -1
@@ -69,7 +69,8 @@ export const serveGuiAndSharedFiles: Koa.Middleware = async (ctx, next) => {
69 if (getUploadTempHash)
70 return !folder.source || !isValidFileName(fn) ? sendErrorPage(ctx, HTTP_NOT_FOUND)
71 : statusCodeForMissingPerm(folder, 'can_upload', ctx) ? null
72 - : ctx.body = await loadFileCached(getUploadTempFor(join(folder.source, fn)), calcHash) // negligible memory leak
72 + : loadFileCached(getUploadTempFor(join(folder.source, fn)), calcHash) // negligible memory leak
73 + .then(hash => ctx.body = hash, e => ctx.status = e?.code === 'ENOENT' ? HTTP_NOT_FOUND : HTTP_SERVER_ERROR)
74 const dest = uploadWriter(folder, folderUri, fn, ctx)
75 if (dest) {
76 ctx.req.pipe(dest).on('error', err => {
tests/test.ts
+1
@@ -282,6 +282,7 @@ describe('after-login', () => {
282 await reqUpload(`${UPLOAD_ROOT}${rel}?partial=1`, 204)()
283 await req(`${UPLOAD_ROOT}${rel}?get=${UPLOAD_TEMP_HASH}`, 401, { jar: {} })()
284 })
285 + test('upload.temp hash missing', req(`${UPLOAD_ROOT}${UPLOAD_DIR}/missing.png?get=${UPLOAD_TEMP_HASH}`, 404))
286 test('file_details.admin', reqApi('get_file_details', { uris: [UPLOAD_DEST] }, res => {
287 const u = res?.details?.[0]?.upload
288 throwIf(!u?.ip ? 'ip' : u?.username !== username ? 'username' : '')