This commit is contained in:
Anaïs Saraiva
2026-08-15 11:50:57 +02:00
parent adf37d43a3
commit a6ff57e5d5
3 changed files with 21 additions and 5 deletions
+1
View File
@@ -132,6 +132,7 @@ curl -F "password=hunter2" -F "[email protected]" http://localhost:3000/api/uploa
"key": "u8wcfcm7", "key": "u8wcfcm7",
"url": "/u8wcfcm7", "url": "/u8wcfcm7",
"originalName": "example.zip", "originalName": "example.zip",
"downloadName": "u8wcfcm7.zip",
"size": 123456, "size": 123456,
"protected": true "protected": true
} }
+10 -4
View File
@@ -155,6 +155,10 @@ function formatDate(iso) {
} }
} }
function displayName(item) {
return item.downloadName || item.originalName || "file";
}
function renderList() { function renderList() {
const list = loadUploads(); const list = loadUploads();
fileList.innerHTML = ""; fileList.innerHTML = "";
@@ -168,8 +172,9 @@ function renderList() {
const nameWrap = document.createElement("div"); const nameWrap = document.createElement("div");
nameWrap.className = "file-name"; nameWrap.className = "file-name";
const name = document.createElement("span"); const name = document.createElement("span");
name.textContent = item.originalName; const shown = displayName(item);
name.title = item.originalName; name.textContent = shown;
name.title = shown;
const lock = document.createElement("span"); const lock = document.createElement("span");
lock.className = "lock"; lock.className = "lock";
lock.textContent = item.protected ? "Protected" : "Public"; lock.textContent = item.protected ? "Protected" : "Public";
@@ -227,7 +232,7 @@ function renderList() {
} }
async function deleteFile(item, onSuccess) { 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; if (!ok) return;
try { try {
const res = await fetch(`/api/files/${item.id}`, { const res = await fetch(`/api/files/${item.id}`, {
@@ -257,7 +262,7 @@ async function deleteFile(item, onSuccess) {
function showResult(data) { function showResult(data) {
progress.classList.add("hidden"); progress.classList.add("hidden");
result.classList.remove("hidden"); result.classList.remove("hidden");
resultName.textContent = data.originalName; resultName.textContent = displayName(data);
resultLock.textContent = data.protected ? "Protected" : "Public"; resultLock.textContent = data.protected ? "Protected" : "Public";
resultLock.classList.toggle("public", !data.protected); resultLock.classList.toggle("public", !data.protected);
resultUrl.value = downloadUrl(data); resultUrl.value = downloadUrl(data);
@@ -266,6 +271,7 @@ function showResult(data) {
key: data.key, key: data.key,
url: data.url, url: data.url,
originalName: data.originalName, originalName: data.originalName,
downloadName: data.downloadName || data.originalName,
size: data.size, size: data.size,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
protected: !!data.protected, protected: !!data.protected,
+10 -1
View File
@@ -2,6 +2,7 @@ import { json, jsonError } from "../http";
import { log } from "../log"; import { log } from "../log";
import { getBoundary, MultipartError, multipartParts, type MultipartPart } from "../multipart"; import { getBoundary, MultipartError, multipartParts, type MultipartPart } from "../multipart";
import { import {
downloadFileName,
hashPassword, hashPassword,
hashSecret, hashSecret,
newFileId, newFileId,
@@ -90,7 +91,15 @@ export async function handleUpload(
const url = publicBaseUrl ? `${publicBaseUrl}/${key}` : `/${key}`; const url = publicBaseUrl ? `${publicBaseUrl}/${key}` : `/${key}`;
log("info", `upload ok id=${id} size=${size} name=${JSON.stringify(originalName)}`); 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) { } catch (err) {
await storage.delete(id); await storage.delete(id);
await storage.deletePartial(id); await storage.deletePartial(id);