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

Đang mở
#128 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, mongodb, next.js, node.js
Lĩnh vực
api, backend, database

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
JavaScript
Star
16
Fork
8
Merge trung bình
4 giờ 24 phút
Pull request đã merge (30 ngày)
10

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của codehubbers/OrbitOS

Tất cả issue của codehubbers/OrbitOS

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.