Add photo attachments to parts

A bag falling apart after forty years still has the part number printed on it,
and the picture carries more than any field you could retype it into. Photos
attach from the part form; on a phone the picker opens the camera directly.

Files live beside the database in the same volume, with only metadata in SQLite
— blobs there bloat the database and complicate the VACUUM INTO backup. The
browser downscales to 2000px before uploading, honouring EXIF orientation via
createImageBitmap, which keeps an image library and its native dependencies out
of the server entirely.

Uploads are sniffed by content rather than trusted by their declared type, so a
file that merely claims to be a JPEG cannot be stored and served back from this
origin as something a browser will execute. SVG is refused for the same reason.
Reads are capped rather than trusting Content-Length, at most 12 photos per
part, and a row that fails to insert takes its file with it.

Deleting a photo or a part removes the files, not just the rows, and
`app.admin prune-images` sweeps anything a crash stranded. The README's backup
procedure now covers both halves; capturing only the database would have
silently lost every photo.

python-multipart returns for the upload, pinned at 0.0.32 — the version removed
earlier was 0.0.20, which carried advisories. Audit is clean.

Two frontend bugs surfaced while testing this in the browser: a photo count
changing left the list row stale, and the part form opened from the list's
cached copy rather than fetching current data.

Checks go from 197 to 271.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jay
2026-08-24 17:03:36 -04:00
parent 59949e91ca
commit 96d2a1a087
9 changed files with 742 additions and 26 deletions
+56
View File
@@ -217,6 +217,62 @@ main { flex: 1; min-width: 0; }
.spec-row { display: flex; gap: 8px; margin-bottom: 7px; align-items: center; }
.spec-row input:first-child { flex: 0 0 38%; }
.shots { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.shot {
position: relative;
width: 96px;
border: 1px solid var(--line);
border-radius: 8px;
overflow: hidden;
background: var(--panel-2);
}
.shot img { display: block; width: 96px; height: 96px; object-fit: cover; cursor: zoom-in; }
.shot .cap {
width: 100%;
border: 0;
border-top: 1px solid var(--line);
border-radius: 0;
background: var(--panel);
font-size: 11px;
padding: 4px 6px;
min-height: 0;
}
.shot .rm {
position: absolute;
top: 3px;
right: 3px;
min-height: 0;
padding: 0 6px;
font-size: 12px;
line-height: 18px;
background: rgba(6, 8, 13, .78);
border-color: transparent;
color: var(--bad);
}
.shot.pending { opacity: .6; }
.shot.pending::after {
content: "queued";
position: absolute;
left: 3px; top: 3px;
background: rgba(6,8,13,.78);
font-size: 10px;
padding: 1px 5px;
border-radius: 4px;
color: var(--dim);
}
.lightbox {
position: fixed;
inset: 0;
background: rgba(4, 6, 10, .93);
display: grid;
place-items: center;
z-index: 200;
padding: 20px;
cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 88vh; border-radius: 10px; }
.lightbox .cap { margin-top: 10px; color: var(--dim); font-size: 13px; text-align: center; }
.history { font-size: 13px; color: var(--dim); }
.history div { padding: 4px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.pos { color: var(--good); }