Store uploaded audio in GridFS instead of base64 inside the File document

Aperta
#128 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, mongodb, next.js, node.js
Ambito
api, backend, database

Direzione di ricerca

Read src/pages/api/files/index.js, src/pages/api/files/[id].js, and src/models/File.js, then trace the upload in src/pages/apps/musicplayer.js and the existing cases in tests/files.api.test.js. Start by checking the current upload and download flows and how MongoDB's GridFSBucket is used in the project. Done means large uploads work, Range requests stream only requested bytes, protections remain in place, existing tests pass with streaming, and the migration is documented.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

backend difficulty: hard performance

New here? Say hi on Discord first, it's the fastest way to get help: https://discord.gg/NW2YZACf4k

Right now an uploaded song is stored as a base64 data URL in the content field of a File document. That works, but it has real limits:

  • MongoDB documents max out at 16 MB, so we cap uploads at 8 MB, and base64 makes files about 33% bigger.
  • Every request that loads the full File document drags the whole song along.
  • GET /api/files/:id decodes the entire file into memory even when the browser asks for a small byte range to seek.

Proposal

  • Store binary files (audio, images) in GridFS using the MongoDB driver's GridFSBucket. The File document keeps metadata and a reference such as gridfsId.
  • Make the upload a streaming multipart/form-data request instead of JSON. multer is already a dependency.
  • Make GET /api/files/:id stream from GridFS and pass Range requests through to openDownloadStream(id, { start, end }).
  • Keep the existing protections from #120: an allow-list of inline content types, nosniff, the sandbox CSP, and owner/collaborator checks.
  • Write a one-off migration script that moves existing base64 audio into GridFS.

Where: src/pages/api/files/index.js, src/pages/api/files/[id].js, src/models/File.js, and the upload in src/pages/apps/musicplayer.js.

Done when

  • Uploads of 30–50 MB work.
  • Seeking only reads the requested bytes.
  • The existing tests in tests/files.api.test.js still pass (adjusted for streaming).
  • The migration is documented in the PR.

This one is meatier. Talk it through on Discord before starting.


Comment "I'd like to take this" and we'll assign you. Questions are welcome in Discord: https://discord.gg/NW2YZACf4k

Lingua principale
JavaScript
Stelle
16
Fork
8
Merge medio
4h 24m
PR unite (30g)
10

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di codehubbers/OrbitOS

Tutte le issue di codehubbers/OrbitOS

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.