feat(server): add box file listing and download routes

Introduce `/box/:id` to render a box page with file metadata, plus
endpoints to download individual files and a “download all” ZIP. Add
helpers to safely list box contents, stream files into a ZIP response,
and infer MIME types/icons for better UI and correct downloads.feat(server): add box file listing and download routes

Introduce `/box/:id` to render a box page with file metadata, plus
endpoints to download individual files and a “download all” ZIP. Add
helpers to safely list box contents, stream files into a ZIP response,
and infer MIME types/icons for better UI and correct downloads.
This commit is contained in:
2026-04-27 17:20:57 +03:00
parent b5f39d714a
commit 6a0b3dbe2f
6 changed files with 526 additions and 1 deletions

160
static/css/box.css Normal file
View File

@@ -0,0 +1,160 @@
.box-window {
width: 640px;
height: 460px;
}
.box-toolbar {
display: flex;
gap: 8px;
height: 40px;
box-sizing: border-box;
padding: 6px 8px;
}
.box-toolbar-button {
width: 116px;
}
.box-address {
display: grid;
grid-template-columns: 58px minmax(0, 1fr);
align-items: center;
height: 28px;
box-sizing: border-box;
padding: 0 8px 6px;
gap: 6px;
font-size: 13px;
line-height: 13px;
}
.box-address code {
min-width: 0;
height: 22px;
display: flex;
align-items: center;
box-sizing: border-box;
padding: 0 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #000000;
background: #ffffff;
border-top: 1px solid #808080;
border-left: 1px solid #808080;
border-right: 1px solid #dfdfdf;
border-bottom: 1px solid #dfdfdf;
font-family: inherit;
}
.box-panel {
flex: 1;
min-height: 0;
margin: 0 8px 8px;
overflow: auto;
}
.box-file-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
gap: 8px;
padding: 10px;
box-sizing: border-box;
}
.box-file {
min-width: 0;
height: 96px;
display: grid;
grid-template-rows: 34px 18px 28px;
justify-items: center;
align-items: center;
box-sizing: border-box;
padding: 8px 6px;
color: #000000;
text-decoration: none;
}
.box-file:hover,
.box-file:focus-visible {
color: #ffffff;
background: #000078;
outline: 1px dotted #ffffff;
outline-offset: -3px;
}
.box-file-icon {
width: 32px;
height: 32px;
object-fit: contain;
image-rendering: pixelated;
}
.box-file-name,
.box-file-meta {
width: 100%;
min-width: 0;
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
}
.box-file-name {
font-size: 13px;
line-height: 13px;
}
.box-file-meta {
align-self: start;
color: #555555;
font-size: 11px;
line-height: 13px;
}
.box-file:hover .box-file-meta,
.box-file:focus-visible .box-file-meta {
color: #ffffff;
}
.box-empty {
margin: 0;
padding: 12px;
color: #555555;
font-size: 13px;
line-height: 15px;
}
.box-statusbar {
grid-template-columns: 1fr 96px;
}
@media (max-width: 600px) {
main {
display: block;
min-height: 100dvh;
}
.box-window {
width: 100vw;
height: 100dvh;
border: 0;
box-shadow: none;
}
.box-titlebar {
height: 24px;
margin: 0;
}
.box-menu {
height: 26px;
}
.box-panel {
margin: 0 6px 8px;
}
.box-file-grid {
grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
}

View File

@@ -1,6 +1,6 @@
.upload-window {
width: 520px;
height: 420px;
height: 456px;
}
.upload-form {
@@ -126,6 +126,55 @@
border-bottom: 2px solid #ffffff;
}
.upload-result {
flex: 0 0 auto;
display: grid;
grid-template-columns: 72px minmax(0, 1fr) 72px;
align-items: center;
gap: 6px;
height: 36px;
box-sizing: border-box;
margin-top: 8px;
padding: 4px 6px;
background: #dfdfdf;
border-top: 1px solid #808080;
border-left: 1px solid #808080;
border-right: 1px solid #ffffff;
border-bottom: 1px solid #ffffff;
font-size: 12px;
line-height: 12px;
}
.upload-result-label {
font-weight: bold;
}
.upload-result-link {
min-width: 0;
overflow: hidden;
color: #000078;
text-overflow: ellipsis;
white-space: nowrap;
}
.upload-result-link.is-empty {
color: #555555;
pointer-events: none;
text-decoration: none;
}
.upload-share-button {
width: 72px;
height: 24px;
font-size: 12px;
line-height: 12px;
}
.upload-share-button:disabled {
color: #808080;
text-shadow: 1px 1px 0 #ffffff;
}
.upload-empty-state {
margin: 0;
padding: 9px 8px;
@@ -264,4 +313,8 @@
.upload-file-list {
min-height: 160px;
}
.upload-result {
grid-template-columns: 64px minmax(0, 1fr) 68px;
}
}

View File

@@ -5,9 +5,12 @@ const dropzone = document.querySelector(".upload-dropzone");
const uploadForm = document.querySelector(".upload-form");
const uploadStatus = document.querySelector(".upload-statusbar span:first-child");
const boxStatus = document.querySelector(".upload-statusbar span:last-child");
const boxLink = document.querySelector("#upload-box-link");
const shareButton = document.querySelector("#upload-share-button");
let selectedFiles = [];
let statusTimer = null;
let shareURL = "";
function formatBytes(bytes) {
const units = ["B", "KB", "MB", "GB"];
@@ -56,6 +59,22 @@ function setBoxStatus(message) {
}
}
function setBoxLink(path) {
shareURL = path ? new URL(path, window.location.origin).toString() : "";
if (boxLink) {
boxLink.href = shareURL || "#";
boxLink.textContent = shareURL || "Waiting for upload";
boxLink.title = shareURL;
boxLink.classList.toggle("is-empty", !shareURL);
boxLink.setAttribute("aria-disabled", shareURL ? "false" : "true");
}
if (shareButton) {
shareButton.disabled = !shareURL;
}
}
function updateFileCount() {
if (fileCount) {
fileCount.textContent = `${selectedFiles.length} ${selectedFiles.length === 1 ? "file" : "files"}`;
@@ -122,6 +141,7 @@ function updateSelectedFiles(files) {
fileList.append(emptyState);
updateStatus("Ready");
setBoxStatus("WarpBox");
setBoxLink("");
return;
}
@@ -133,6 +153,7 @@ function updateSelectedFiles(files) {
fileList.append(fragment);
updateStatus("Files selected");
setBoxStatus("WarpBox");
setBoxLink("");
}
async function createBox() {
@@ -246,6 +267,7 @@ if (uploadForm) {
try {
const box = await createBox();
setBoxStatus(box.box_url);
setBoxLink(box.box_url);
await Promise.allSettled(selectedFiles.map((selectedFile) => {
return uploadFile(box.box_id, selectedFile, () => {
@@ -267,3 +289,27 @@ if (uploadForm) {
}
});
}
if (shareButton) {
shareButton.addEventListener("click", async () => {
if (!shareURL) {
return;
}
try {
if (navigator.share) {
await navigator.share({
title: "WarpBox download",
text: "Download these files from WarpBox",
url: shareURL,
});
return;
}
await navigator.clipboard.writeText(shareURL);
updateStatus("Link copied");
} catch (error) {
updateStatus("Share cancelled");
}
});
}