Media: name files when saving, and rename them in the library (file and references)

Every upload and save (Upload, Frame at, Video thumbnails, a clip's
Save to library) has a prefilled Name box; the name is also the
readable part of the file's name, plus a short random ending. Fetch
preview names its picture after the page. Rename on the Media page
changes both, moving the file and its small copy and pointing every
record that names it at the new path in one transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-08 15:47:30 -05:00
parent 14a22ca44d
commit 687ba898f6
9 changed files with 475 additions and 74 deletions

View file

@ -27,6 +27,18 @@ in the `media` table (`server/src/migrations/028_media.sql`).
(`.vtt`, kept as they are, always in `captions/`). The type is read
from the file's contents, not its name: a captions file has to start
with `WEBVTT`.
- Every upload and save asks for a **Name** (prefilled: the file's own
name, "Video frame at 1:23", a clip's title and span). It's the
library's name and the readable part of the file's, plus a short
random ending: `images/spring-retreat-group-3f9c1a.webp`
(`slugify` and `storedNameFor` in `server/src/media.js`). Fetch preview
names its picture after the page's title.
- **Rename** (Media page, editors and up) changes both. The file and its
small copy move to a new name, and every record that names the file is
pointed at it in the same step (the same search the delete check
uses). Anything outside the site still holding the old address (a
sent newsletter, a shared link) stops working. A rename that only
changes capitals or punctuation keeps the file where it is.
- Editors and up can upload. Admins and up can delete. The Media page
shows which tables still use a file before deleting it, because
nothing stops a file a record uses from being deleted.
@ -106,7 +118,9 @@ which git ignores). The API serves `/uploads/` itself, and Vite proxies
}
```
Filenames are random and never reused, so `immutable` is safe.
Every stored name ends in a random part and a new one is never an
existing file's, so `immutable` is safe; a rename makes a new name
rather than changing a file in place.
4. `sharp` is a server dependency now: run `pnpm install` in
`/srv/ngu-api` after the deploy. It ships prebuilt Linux binaries,