progress bar + better ui

This commit is contained in:
Ludwig Lehnert
2026-03-27 20:08:40 +01:00
parent 31c7f92d7c
commit 83fbeff16c
8 changed files with 474 additions and 29 deletions

View File

@@ -31,6 +31,28 @@ function contentDisposition(filename) {
return `attachment; filename="${fallback}"; filename*=UTF-8''${encoded}`;
}
function escapeLike(value) {
return String(value || '').replace(/[\\%_]/g, '\\$&');
}
async function findUploadRow(fileName) {
const exactRow = await get('SELECT id, original_name, stored_path FROM uploads WHERE stored_name = ?', [
fileName,
]);
if (exactRow || fileName.includes('.')) {
return exactRow;
}
const likePattern = `${escapeLike(fileName)}.%`;
return get(
`SELECT id, original_name, stored_path FROM uploads
WHERE stored_name = ? OR stored_name LIKE ? ESCAPE '\\'
ORDER BY CASE WHEN stored_name = ? THEN 0 ELSE 1 END, id DESC
LIMIT 1`,
[fileName, likePattern, fileName]
);
}
export async function GET(request, { params }) {
await runCleanupIfNeeded();
@@ -40,7 +62,7 @@ export async function GET(request, { params }) {
return new NextResponse('Ungültiger Dateiname', { status: 400 });
}
const row = await get('SELECT id, original_name, stored_path FROM uploads WHERE stored_name = ?', [fileName]);
const row = await findUploadRow(fileName);
let filePath;
let downloadName;