Keep uploaded images in folders by what they're for

logos/ for logo and icon fields, thumbnails/ for previews the site
saves (link previews, Drive first pages), images/ for everything else;
each small copy beside its image. Images from before folders are
sorted once at boot by their uses, and every record naming them is
rewritten in one transaction after the files move.

The Media page and image pickers get a tab per folder; a picker opens
on its field's folder and uploads there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 22:29:22 -05:00
parent 4b249c9e52
commit 9854da965e
14 changed files with 283 additions and 51 deletions

View file

@ -23,10 +23,37 @@ in the `media` table (`server/src/migrations/028_media.sql`).
Limits and sizes are constants at the top of `server/src/media.js`.
## Folders
Images are kept in folders by what they're for (`FOLDERS` in
`server/src/media.js`), and the paths records store include them:
| Folder | What goes in it |
| --- | --- |
| `logos/` | Uploads from logo and icon fields (organization, team, award and event logos, the favicon and home-screen icon): the fields with `folder: "logos"` in `src/lib/adminSchema/` |
| `images/` | Every other upload: photos, backgrounds, covers, block images |
| `thumbnails/` | Pictures the site saves by itself: link previews (Fetch preview) and Drive files' first pages |
Each image's `-640.webp` small copy sits beside it. Video and audio
clips (Tools → Video clips) stay in the root. The Media page and every
image picker have a tab per folder; a picker opens on its field's
folder, and uploads there.
**Images from before folders** (a bare name in the root) are sorted
once, when the server first starts with this version: a logo or icon
field names it → `logos/`; saved as a preview → `thumbnails/`; anything
else → `images/`. Every record that names it is rewritten to the new
path in one transaction, after the files move (if that fails, the files
move back). The journal says `uploads: moved N image(s) into folders`.
Back up the database and uploads before that first start; nothing is
needed after.
nginx needs no change: `location /uploads/` already serves the folders.
## Files copied in by hand
A file put straight into the uploads directory (with `scp`, say) shows
up in the library the next time the Media page or an image picker opens:
A file put straight into the uploads directory, or into one of its
folders (with `scp`, say), shows up in the library the next time the Media page or an image picker opens:
the server registers any image it finds there without a record, under
the file's own name, kept as it is (not resized). Anything that isn't a
JPEG, PNG, GIF, WebP or SVG is ignored. A record can name such a file by