Public: anyone can read this; the crew can change it.
The app's Drop page takes a file dragged onto it, with the forge's remaining quota shown before the upload starts #13475
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13423-the-app-s-drop-page-takes-a-file-dragged → main 4 commits fork 3 threads · 3 unresolved
6 files
changed +103
−16
docs/design/areas/drop.md +3 −4
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | # The drop |
| 2 | 2 | |
| 3 | Its own page, `/:owner/:name/drop`, reached from the app page's links. Two classes in `src/web/style/content.ts`, | |
| 3 | Its own page, `/:owner/:name/drop`, reached from the app page's links. Three classes in `src/web/style/content.ts`, | |
| 4 | 4 | drawn from existing tokens: `.drop-extract` (a file's CSV head, PDF text or SQL schema, small and scrollable, inside a |
| 5 | `details` under the file's row) and `.drop-thumb` (an image's thumbnail, a fixed 96x64 box so the row never shifts). | |
| 6 | Everything else is the existing table, badge, form and button: the upload is a plain file input with a **Send** button, | |
| 7 | no drop target drawn around it. | |
| 5 | `details` under the file's row) and `.drop-thumb` (an image's thumbnail, a fixed 96x64 box so the row never shifts) and `.drop-zone` (the upload form itself, a plain row under a hairline, of fixed minimum height, that a dragged file may land on; `.drop-over` turns the hairline to the accent and tints the row with `--muted`, and its status line has reserved height, so nothing shifts). | |
| 6 | Everything else is the existing table, badge, form and button: the upload is a plain file input with a **Send** button. |
docs/features/drop.md +1 −1
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | A private place per app for what the crew needs to read and cannot find in the repository: database dumps, CSVs, PDFs, CAD files, images, video. Only people who can write the app, and its crew, see it; nothing in it is ever served publicly, and to anyone else (anonymous included) it is `not_found`. |
| 4 | 4 | |
| 5 | 1. Open the app's page and follow **Drop** (`/<owner>/<name>/drop`): it shows the forge's quota (used of total, shared by every app), then a form: choose files, press **Send**. It works with no script (a multipart POST, up to 32 MiB a request); with script the same button streams each file to the API, so a file of any size up to the limit goes without a reload. | |
| 5 | 1. Open the app's page and follow **Drop** (`/<owner>/<name>/drop`): it shows the forge's quota (used of total, shared by every app), then a form: choose files, press **Send**. It works with no script (a multipart POST, up to 32 MiB a request); with script the same button streams each file to the API, so a file of any size up to the limit goes without a reload. With script you can also drag files from your desktop onto the upload row: the page checks each against the file limit and the forge's remaining space before sending, shows a progress line, and reloads when done; a refusal is said in the same words as the API's and nothing is stored. | |
| 6 | 6 | 2. Each file is a row with its kind, size and a cheap extract: a CSV's first rows, a PDF's text, a SQL dump's `CREATE TABLE` schema, an image's size and a thumbnail. Large or binary files have no extract: the crew is told their path. |
| 7 | 7 | 3. The crew's next run is told the folder and each file's name, kind and size in its brief — never the contents — and reads them with its own tools. The folder is mounted into the run's sandbox read-only (`readAllow` in `src/crew/sandbox.ts`); every other app's drop stays denied. |
| 8 | 8 | 4. By API: `curl -T dump.sql -H "authorization: Bearer $TOKEN" "$FORGE_URL/api/v1/repos/<owner>/<name>/drop?name=dump.sql"` streams a body to disk (`GET …/drop` lists, `GET …/drop/<file>?range=0-4096` reads up to 64 KB of a text file, `DELETE …/drop/<file>` removes). By MCP: the `drop` tool, `action: list|put|read|remove`. In the terminal: **Drop** in the palette while the repository is open (`j`/`k` move, `x` removes; a terminal has no drag, so putting a file in is the page's, the API's or the MCP tool's), live as files come and go. |
src/web/studio/drop.ts +19 −10
| @@ -42,7 +42,7 @@ export function dropPageGet(ctx: Ctx): Response { | ||
| 42 | 42 | const body = html`${pageHead("Drop")} |
| 43 | 43 | <p>Files your crew reads and the repository cannot hold. Only people who can write this app see them.</p> |
| 44 | 44 | <p class="muted small">${fileSize(quota.usedBytes)} of ${fileSize(quota.quotaBytes)} used, shared by every app on this forge. Up to ${fileSize(quota.fileMaxBytes)} a file.</p> |
| 45 | <form method="post" action="${base}/drop" enctype="multipart/form-data" class="row" data-drop="${api}" data-room="${String(room)}" data-max="${String(quota.fileMaxBytes)}"> | |
| 45 | <form method="post" action="${base}/drop" enctype="multipart/form-data" class="row drop-zone" data-drop="${api}" data-too-large="${PUT_WORDS.too_large}" data-full="${PUT_WORDS.quota}" data-room="${String(room)}" data-max="${String(quota.fileMaxBytes)}"> | |
| 46 | 46 | <input type="file" name="file" multiple required aria-label="Files to drop" /> |
| 47 | 47 | ${btn("Send")} |
| 48 | 48 | <span class="muted small" data-drop-say role="status" aria-live="polite"></span> |
outdated
Principle 1/8: 'or drag files onto this box' explains the affordance a second time, and with JavaScript off a dropped file would make the browser navigate to it. Drop the sentence or show it only when script has run (e.g. set by dropJs). |
||
| @@ -114,15 +114,24 @@ export async function removeDropPage(ctx: Ctx): Promise<Response> { | ||
| 114 | 114 | */ |
| 115 | 115 | export const dropJs = `(function(){var f=document.querySelector('form[data-drop]');if(!f)return; |
| 116 | 116 | var url=f.getAttribute('data-drop'),room=+f.getAttribute('data-room'),max=+f.getAttribute('data-max'); |
| 117 | var big=f.getAttribute('data-too-large'),full=f.getAttribute('data-full'); | |
| 117 | 118 | var input=f.querySelector('input[type=file]'),say=f.querySelector('[data-drop-say]'); |
| 119 | say.textContent='Drag files onto this row to send them.'; | |
| 118 | 120 | function clean(n){n=n.replace(/[^A-Za-z0-9._ +()-]/g,'_').replace(/^[^A-Za-z0-9]+/,'').slice(-100).replace(/^[^A-Za-z0-9]+/,'');return n||'file'} |
| 119 | f.addEventListener('submit',async function(e){ | |
| 120 | e.preventDefault(); | |
| 121 | for(var x of Array.from(input.files)){ | |
| 122 | if(x.size>max){say.textContent=x.name+': over the '+(max/1048576)+' MB a file may be';return} | |
| 123 | if(x.size>room){say.textContent=x.name+': more than the room left in this forge\\u2019s drop';return} | |
| 121 | function send(x){return new Promise(function(done){ | |
| 122 | var q=new XMLHttpRequest();q.open('POST',url+'?name='+encodeURIComponent(clean(x.name))); | |
| 123 | q.upload.onprogress=function(e){if(e.lengthComputable)say.textContent='Sending '+x.name+': '+Math.floor(e.loaded*100/e.total)+'%'}; | |
| 124 | q.onload=function(){if(q.status<300)return done(true);var j={};try{j=JSON.parse(q.responseText)}catch(_){}say.textContent=x.name+': '+(j.message||q.status);done(false)}; | |
| 125 | q.onerror=function(){say.textContent=x.name+': not sent';done(false)}; | |
| 126 | q.send(x)})} | |
| 127 | async function go(list){ | |
| 128 | for(var x of Array.from(list)){ | |
| 129 | if(x.size>max){say.textContent=x.name+': '+big;return} | |
| 130 | if(x.size>room){say.textContent=x.name+': '+full;return} | |
| 124 | 131 | room-=x.size;say.textContent='Sending '+x.name+'\\u2026'; |
| 125 | try{var r=await fetch(url+'?name='+encodeURIComponent(clean(x.name)),{method:'POST',body:x,credentials:'same-origin'}); | |
| 126 | if(!r.ok){var j={};try{j=await r.json()}catch(_){}say.textContent=x.name+': '+(j.message||r.status);return}} | |
| 127 | catch(_){say.textContent=x.name+': not sent';return}} | |
| 128 | location.reload()})})();`; | |
| 132 | if(!await send(x))return} | |
| 133 | location.reload()} | |
| 134 | f.addEventListener('submit',function(e){e.preventDefault();go(input.files)}); | |
| 135 | ['dragenter','dragover'].forEach(function(t){f.addEventListener(t,function(e){e.preventDefault();f.classList.add('drop-over')})}); | |
| 136 | ['dragleave','drop'].forEach(function(t){f.addEventListener(t,function(e){e.preventDefault();f.classList.remove('drop-over')})}); | |
| 137 | f.addEventListener('drop',function(e){if(e.dataTransfer&&e.dataTransfer.files.length)go(e.dataTransfer.files)})})();`; |
src/web/style/content.ts +4
| @@ -483,6 +483,10 @@ form.inline { display: inline; margin-left: auto; } | ||
| 483 | 483 | .drop-extract { margin: 4px 0 0; max-height: 7.5em; overflow: auto; white-space: pre-wrap; word-break: break-word; } |
| 484 | 484 | .drop-thumb { display: block; width: 96px; height: 64px; object-fit: cover; margin-top: 4px; border-radius: var(--radius); } |
| 485 | 485 | |
| 486 | .drop-zone { padding: 12px 0; margin: 12px 0; min-height: 64px; border-top: 1px solid var(--border); } | |
| 487 | .drop-zone.drop-over { border-top-color: var(--accent); background: var(--muted); } | |
outdated
|
||
| 488 | .drop-zone [data-drop-say] { flex-basis: 100%; min-height: 1.4em; } | |
| 489 | ||
| 486 | 490 | /* A notebook (render/notebook.ts): cells are rows with space between, never boxes. */ |
| 487 | 491 | .nb-cell { margin: 0 0 28px; min-width: 0; } |
| 488 | 492 | .nb pre { max-width: 100%; overflow-x: auto; margin: 8px 0; } |
test/drop-page.test.ts added +75
| @@ -0,0 +1,75 @@ | ||
| 1 | /** | |
| 2 | * The drop page (#13423): the quota is said server-side before any upload, and the form carries a | |
| 3 | * drop target and the refusal words. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { PUT_WORDS } from "../src/actions/drop.ts"; | |
| 12 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 13 | import { promote } from "./helpers/members.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { dropJs } from "../src/web/studio/drop.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | let dir: string; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | ||
| 24 | beforeAll(async () => { | |
| 25 | dir = await mkdtemp(join(tmpdir(), "drop-page-")); | |
| 26 | app = createApp({ dataDir: dir, port: 0, host: "forge.test" }); | |
| 27 | servers = await serve(app); | |
| 28 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "cy", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 29 | if (!made.ok) throw new Error(made.error); | |
| 30 | promote(app.db, made.value); | |
| 31 | const r = await createRepo(app, made.value, { name: "paper", visibility: "public", description: "" }); | |
| 32 | if (!r.ok) throw new Error(String(r.error)); | |
| 33 | const row = insertApp(app.db, { repoId: r.value.id, slug: "paper", access: "public" }); | |
| 34 | if (!row.ok) throw new Error(row.error); | |
| 35 | }, 60_000); | |
| 36 | afterAll(async () => { | |
| 37 | servers?.stop(); | |
| 38 | app?.close(); | |
| 39 | await rm(dir, { recursive: true, force: true }); | |
| 40 | }); | |
| 41 | ||
| 42 | test("the page names the quota and the drop target before any upload, and the script knows the refusal words", async () => { | |
| 43 | const r = await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "cy", password: "a-good-passphrase" }), redirect: "manual" }); | |
| 44 | const cookie = `${(r.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=dev`; | |
| 45 | const page = await (await fetch(`${servers.url}/cy/paper/drop`, { headers: { cookie } })).text(); | |
| 46 | expect(page).toContain("0 B of "); | |
| 47 | expect(page).toContain("used, shared by every app"); | |
| 48 | expect(page).toContain("drop-zone"); | |
| 49 | expect(page).not.toContain("or drag files onto this box"); | |
| 50 | expect(page).toContain("data-room="); | |
| 51 | expect(page).toContain('enctype="multipart/form-data"'); | |
| 52 | expect(page).toContain(`data-full="${PUT_WORDS.quota}"`.replace(/'/g, "'")); | |
| 53 | expect(dropJs).toContain("dataTransfer.files"); | |
| 54 | expect(dropJs).toContain("upload.onprogress"); | |
| 55 | }); | |
| 56 | ||
| 57 | test("a refused put through the page's POST stores nothing and says the API's words", async () => { | |
| 58 | const r = await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "cy", password: "a-good-passphrase" }), redirect: "manual" }); | |
| 59 | const cookie = `${(r.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=dev`; | |
| 60 | const post = (name: string, size: number) => fetch(`${servers.url}/api/v1/repos/cy/paper/drop?name=${name}`, { method: "POST", headers: { cookie, origin: servers.url }, body: new Uint8Array(size).fill(65) }); | |
| 61 | const list = async () => ((await (await fetch(`${servers.url}/api/v1/repos/cy/paper/drop`, { headers: { cookie } })).json()) as { files: { name: string }[] }).files.map((f) => f.name); | |
| 62 | process.env["FORGE_DROP_QUOTA_MB"] = String(100 / 1048576); | |
| 63 | try { | |
| 64 | const full = await post("big.bin", 5000); | |
| 65 | expect(full.status).toBe(413); | |
| 66 | expect(await full.json()).toMatchObject({ error: "quota", message: PUT_WORDS.quota }); | |
| 67 | expect(await list()).not.toContain("big.bin"); | |
| 68 | } finally { | |
| 69 | delete process.env["FORGE_DROP_QUOTA_MB"]; | |
| 70 | } | |
| 71 | const empty = await post("none.txt", 0); | |
| 72 | expect(empty.status).toBe(422); | |
| 73 | expect(await empty.json()).toMatchObject({ error: "empty", message: PUT_WORDS.empty }); | |
| 74 | expect(await list()).not.toContain("none.txt"); | |
| 75 | }); |
test/drop.test.ts +1 −1
| @@ -208,7 +208,7 @@ describe("the drop", () => { | ||
| 208 | 208 | expect(mine).toContain("of 2048.0 MB used"); |
| 209 | 209 | expect(mine).toMatch(/<form method="post" action="\/cy\/paper\/drop" enctype="multipart\/form-data"/); |
| 210 | 210 | expect(mine).toMatch(/action="[^"]*\/drop\/remove[^"]*"/); |
| 211 | expect(mine).not.toContain("drop-zone"); | |
| 211 | expect(mine).toContain("drop-zone"); // #13423: the form is itself a drop target now | |
| 212 | 212 | const appPage = await (await fetch(`${servers.url}/cy/paper`, { headers: { cookie } })).text(); |
| 213 | 213 | expect(appPage).toContain('href="/cy/paper/drop"'); |
| 214 | 214 | expect(appPage).not.toContain("parts.csv"); |
new above
offline
Principle 6: the form becomes a bordered box (
.drop-zone). A hairline where the thing ends, not a box around it. Make the target a plain row with space and a highlight on drag-over.