veza/veza-backend-api/internal/core/track
senke 7974517c03 feat(backend,web): single source of truth for upload-size limits
Second item of the v1.0.6 backlog. The "front 500MB vs back 100MB" mismatch
flagged in the v1.0.5 audit turned out to be a misread — every live pair
was already aligned (tracks 100/100, cloud 500/500, video 500/500). The
real bug is architectural: the same byte values were duplicated in five
places (`track/service.go`, `handlers/upload.go:GetUploadLimits`,
`handlers/education_handler.go`, `upload-modal/constants.ts`, and
`CloudUploadModal.tsx`), drifting silently as soon as anyone tuned one.

Backend — one canonical spec at `internal/config/upload_limits.go`:
  * `AudioLimit`, `ImageLimit`, `VideoLimit` expose `Bytes()`, `MB()`,
    `HumanReadable()`, `AllowedMIMEs` — read lazily from env
    (`MAX_UPLOAD_AUDIO_MB`, `MAX_UPLOAD_IMAGE_MB`, `MAX_UPLOAD_VIDEO_MB`)
    with defaults 100/10/500.
  * Invalid / negative / zero env values fall back to the default;
    unreadable config can't turn the limit off silently.
  * `track.Service.maxFileSize`, `track_upload_handler.go` error string,
    `education_handler.go` video gate, and `upload.go:GetUploadLimits`
    all read from this single source. Changing `MAX_UPLOAD_AUDIO_MB`
    retunes every path at once.

Frontend — new `useUploadLimits()` hook:
  * Fetches GET `/api/v1/upload/limits` via react-query (5 min stale,
    30 min gc), one retry, then silently falls back to baked-in
    defaults that match the backend compile-time defaults so the
    dropzone stays responsive even without the network round-trip.
  * `useUploadModal.ts` replaces its hardcoded `MAX_FILE_SIZE`
    constant with `useUploadLimits().audio.maxBytes`, and surfaces
    `audioMaxHuman` up to `UploadModal` → `UploadModalDropzone` so
    the "max 100 MB" label and the "too large" error toast both
    display the live value.
  * `MAX_FILE_SIZE` constant kept as pure fallback for pre-network
    render (documented as such).

Tests
  * 4 Go tests on `config.UploadLimit` (defaults, env override, invalid
    env → fallback, non-empty MIME lists).
  * 4 Vitest tests on `useUploadLimits` (sync fallback on first render,
    typed mapping from server payload, partial-payload falls back
    per-category, network failure keeps fallback).
  * Existing `trackUpload.integration.test.tsx` (11 cases) still green.

Out of scope (tracked for later):
  * `CloudUploadModal.tsx` still has its own 500MB hardcoded — cloud
    uploads accept audio+zip+midi with a different category semantic
    than the three in `/upload/limits`. Unifying those deserves its
    own design pass, not a drive-by.
  * No runtime refactor of admin-provided custom category limits —
    the current tri-category split covers every upload we ship today.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-16 19:37:37 +02:00
..
handler.go feat(v0.10.3): Commentaires & Interactions Sociales - F201-F215 2026-03-09 10:30:47 +01:00
handler_additional_test.go fix(backend,web): restore audio playback via /stream fallback 2026-04-16 14:52:26 +02:00
handler_error_format_test.go refonte: backend-api go first; phase 1 2025-12-12 21:34:34 -05:00
handler_mustget_test.go refonte: backend-api go first; phase 1 2025-12-12 21:34:34 -05:00
handler_ownership_test.go refonte: backend-api go first; phase 1 2025-12-12 21:34:34 -05:00
handler_test.go fix(backend): remediation plan — tests, playback_analytics, job queue, gamification 2026-02-17 16:01:45 +01:00
service.go feat(backend,web): single source of truth for upload-size limits 2026-04-16 19:37:37 +02:00
service_async_test.go stabilizing apps/web: THIRD BATCH - FIXED Playwright 2025-12-21 18:55:51 -05:00
service_n1_test.go stabilizing veza-backend-api: phase 1 2025-12-16 11:23:49 -05:00
service_test.go [T0-006] test(backend): Ajout tests pour frontend_log_handler 2026-01-04 01:44:22 +01:00
track_analytics_handler.go v0.9.4 2026-03-05 23:03:43 +01:00
track_batch_service.go v0.9.4 2026-03-05 23:03:43 +01:00
track_crud_handler.go style(backend): gofmt -w on 85 files (whitespace only) 2026-04-14 12:22:14 +02:00
track_handler_integration_test.go [BE-API-002] api: Implement playlist collaborators endpoints 2025-12-23 01:41:43 +01:00
track_hls_handler.go fix(backend,web): restore audio playback via /stream fallback 2026-04-16 14:52:26 +02:00
track_search_handler.go chore(release): v0.602 — Payout, Dette Technique & Tests E2E 2026-02-23 22:32:01 +01:00
track_social_handler.go feat(v0.10.5): Notifications complètes — F551-F555 2026-03-10 10:02:21 +01:00
track_upload_handler.go feat(backend,web): single source of truth for upload-size limits 2026-04-16 19:37:37 +02:00
track_upload_integration_test.go incus deployement fully implemented, Makefile updated and make fmt ran 2026-01-13 19:47:57 +01:00
track_waveform_handler.go feat(v0.501): Sprint 5 -- integration, tests, and cleanup 2026-02-22 18:40:07 +01:00