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",
"url": "/u8wcfcm7",
"originalName": "example.zip",
"downloadName": "u8wcfcm7.zip",
"size": 123456,
"protected": true
}
+10 -4
View File
@@ -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,
+10 -1
View File
@@ -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);