Attachments for guides (#97) #117

Merged
miko merged 1 commit from feature/97-attachments into development 2026-11-05 15:28:55 +01:00
Owner

Closes #97.

  • Several files per guide (3D models, drawings, G-code, manuals, firmware), each with a name and optional description; added (chosen or dropped), renamed and removed in the guide's properties, saved at once into the working copy.
  • The reading view lists them with type and size below the description; print and PDF name them with a hint to download them at the guide's address.
  • Stored in UPLOAD_DIR under attachments/, served by /media/attachments/<id> with the guide's visibility check (ADR-0006). Always a download: application/octet-stream, Content-Disposition: attachment (UTF-8 name plus ASCII fallback), nosniff, sandboxing CSP.
  • Programs and scripts are refused by the fixed extension list (trailing dots and spaces included, which Windows drops) and every file with an MZ header; firmware and G-code stay allowed, ELF is not detected.
  • New setting "Maximum attachment size in MB", 50 by default (1–1024). Uploads go to POST /media/attachments with the raw file as body instead of a Server Action, whose body limit is fixed at build time; the route checks Origin.
  • Attachments are versioned content: versions store them, GuideVersionAttachment lets /media find ones only a version still has, discard and restore bring them back, and a file is deleted only when neither a working copy nor a version references it.
  • New ADR-0021; GLOSSARY gains Attachment; CHANGELOG and German translations updated. Migration 20261105220000_add_guide_attachments adds two tables.

Tests: unit tests for the rules (src/attachments/rules.test.ts), access (src/attachments/access.test.ts), versioned content and the setting; e2e in e2e/attachments.spec.ts. Typecheck, lint, 490 unit and 63 e2e tests pass.

Open questions:

  • Attachments cannot be reordered; they stay in upload order.
  • Uploads are held in memory while checked and written; fine at 50 MB, costly near the 1024 MB maximum.
  • Public attachments are cached public, immutable like image variants, so shared caches may keep them after a guide turns internal.

🤖 Generated with Claude Code

Closes #97. - Several files per guide (3D models, drawings, G-code, manuals, firmware), each with a name and optional description; added (chosen or dropped), renamed and removed in the guide's properties, saved at once into the working copy. - The reading view lists them with type and size below the description; print and PDF name them with a hint to download them at the guide's address. - Stored in `UPLOAD_DIR` under `attachments/`, served by `/media/attachments/<id>` with the guide's visibility check (ADR-0006). Always a download: `application/octet-stream`, `Content-Disposition: attachment` (UTF-8 name plus ASCII fallback), `nosniff`, sandboxing CSP. - Programs and scripts are refused by the fixed extension list (trailing dots and spaces included, which Windows drops) and every file with an `MZ` header; firmware and G-code stay allowed, ELF is not detected. - New setting "Maximum attachment size in MB", 50 by default (1–1024). Uploads go to `POST /media/attachments` with the raw file as body instead of a Server Action, whose body limit is fixed at build time; the route checks `Origin`. - Attachments are versioned content: versions store them, `GuideVersionAttachment` lets `/media` find ones only a version still has, discard and restore bring them back, and a file is deleted only when neither a working copy nor a version references it. - New ADR-0021; GLOSSARY gains **Attachment**; CHANGELOG and German translations updated. Migration `20261105220000_add_guide_attachments` adds two tables. Tests: unit tests for the rules (`src/attachments/rules.test.ts`), access (`src/attachments/access.test.ts`), versioned content and the setting; e2e in `e2e/attachments.spec.ts`. Typecheck, lint, 490 unit and 63 e2e tests pass. Open questions: - Attachments cannot be reordered; they stay in upload order. - Uploads are held in memory while checked and written; fine at 50 MB, costly near the 1024 MB maximum. - Public attachments are cached `public, immutable` like image variants, so shared caches may keep them after a guide turns internal. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Files can be attached to a guide for download (3D models, drawings,
G-code, manuals, firmware), each with a name and optional description.
They are part of the working copy and its versions; their files stay as
long as a working copy or a version references them. The reading view
lists them with type and size, print and PDF name them with a hint.

Downloads go through the guarded /media route, always as attachment with
nosniff; programs and scripts are refused by extension (trailing dots
included) and by the MZ header. Uploads go to a route handler, since the
largest attachment is a new setting (50 MB at first). ADR-0021.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
miko merged commit 6a052f9b34 into development 2026-11-05 15:28:55 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MassiveDynamic/kataba!117
No description provided.