From a6ff57e5d5a2205753b2073faf5581ffe6b0a8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Saraiva?= <53227802+Kisakay@users.noreply.github.com> Date: Sat, 15 Aug 2026 11:50:57 +0200 Subject: [PATCH] fixes --- README.md | 1 + src/public/app.js | 14 ++++++++++---- src/routes/upload.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2959af3..3bfda49 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ curl -F "password=hunter2" -F "file=@secret.zip" http://localhost:3000/api/uploa "key": "u8wcfcm7", "url": "/u8wcfcm7", "originalName": "example.zip", + "downloadName": "u8wcfcm7.zip", "size": 123456, "protected": true } diff --git a/src/public/app.js b/src/public/app.js index be7d60d..63b17bb 100644 --- a/src/public/app.js +++ b/src/public/app.js @@ -155,6 +155,10 @@ function formatDate(iso) { } } +function displayName(item) { + return item.downloadName || item.originalName || "file"; +} + function renderList() { const list = loadUploads(); fileList.innerHTML = ""; @@ -168,8 +172,9 @@ function renderList() { const nameWrap = document.createElement("div"); nameWrap.className = "file-name"; const name = document.createElement("span"); - name.textContent = item.originalName; - name.title = item.originalName; + const shown = displayName(item); + name.textContent = shown; + name.title = shown; const lock = document.createElement("span"); lock.className = "lock"; lock.textContent = item.protected ? "Protected" : "Public"; @@ -227,7 +232,7 @@ function renderList() { } async function deleteFile(item, onSuccess) { - const ok = window.confirm(`Delete "${item.originalName}" permanently? This cannot be undone.`); + const ok = window.confirm(`Delete "${displayName(item)}" permanently? This cannot be undone.`); if (!ok) return; try { const res = await fetch(`/api/files/${item.id}`, { @@ -257,7 +262,7 @@ async function deleteFile(item, onSuccess) { function showResult(data) { progress.classList.add("hidden"); result.classList.remove("hidden"); - resultName.textContent = data.originalName; + resultName.textContent = displayName(data); resultLock.textContent = data.protected ? "Protected" : "Public"; resultLock.classList.toggle("public", !data.protected); resultUrl.value = downloadUrl(data); @@ -266,6 +271,7 @@ function showResult(data) { key: data.key, url: data.url, originalName: data.originalName, + downloadName: data.downloadName || data.originalName, size: data.size, createdAt: new Date().toISOString(), protected: !!data.protected, diff --git a/src/routes/upload.ts b/src/routes/upload.ts index 05984d4..9366cd5 100644 --- a/src/routes/upload.ts +++ b/src/routes/upload.ts @@ -2,6 +2,7 @@ import { json, jsonError } from "../http"; import { log } from "../log"; import { getBoundary, MultipartError, multipartParts, type MultipartPart } from "../multipart"; import { + downloadFileName, hashPassword, hashSecret, newFileId, @@ -90,7 +91,15 @@ export async function handleUpload( const url = publicBaseUrl ? `${publicBaseUrl}/${key}` : `/${key}`; log("info", `upload ok id=${id} size=${size} name=${JSON.stringify(originalName)}`); - return json({ id, key, url, originalName, size, protected: !!passwordHash }); + return json({ + id, + key, + url, + originalName, + downloadName: downloadFileName(key, originalName), + size, + protected: !!passwordHash, + }); } catch (err) { await storage.delete(id); await storage.deletePartial(id);