Changeset fbc8628 in Klonkt


Ignore:
Timestamp:
06/18/2026 08:48:18 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
91d948c
Parents:
03af7f8
Message:

Audio upload: WAV up to 100 MB (other formats remain 50 MB)

WAV is uncompressed → 50 MB was too tight. multer ceiling now 100 MB
(the highest), with a per-type check in the handler: .wav may be 100 MB,
compressed formats stay at 50 MB. Dropzone text updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/routes/admin-audio.js

    r03af7f8 rfbc8628  
    3737const ALLOWED_AUDIO_EXT = new Set(['.mp3', '.m4a', '.mp4', '.aac', '.oga', '.ogg', '.opus', '.flac', '.wav', '.webm']);
    3838const ALLOWED_COVER_EXT = new Set(['.jpg', '.jpeg', '.png', '.webp', '.gif']);
    39 const MAX_AUDIO_BYTES = 50 * 1024 * 1024;  // 50 MB
    40 const MAX_COVER_BYTES = 5 * 1024 * 1024;   // 5 MB
     39const MAX_AUDIO_BYTES = 50 * 1024 * 1024;   // 50 MB — gecomprimeerde formaten (mp3/m4a/ogg/…)
     40const MAX_WAV_BYTES   = 100 * 1024 * 1024;  // 100 MB — WAV is ongecomprimeerd, dus ruimer
     41const MAX_COVER_BYTES = 5 * 1024 * 1024;    // 5 MB
     42
     43// Per-bestand bovengrens op basis van extensie. multer's globale limiet is de
     44// hoogste (WAV); de echte controle per type gebeurt in de upload-handler.
     45const audioByteLimitFor = (ext) => (ext.toLowerCase() === '.wav' ? MAX_WAV_BYTES : MAX_AUDIO_BYTES);
    4146
    4247// Multer routes audio + cover into separate dirs based on field name.
     
    5358const upload = multer({
    5459  storage,
    55   limits: { fileSize: MAX_AUDIO_BYTES }, // upper bound — per-field check below
     60  limits: { fileSize: MAX_WAV_BYTES }, // hoogste bovengrens (WAV) — per-type check in de handler
    5661  fileFilter: (req, file, cb) => {
    5762    const ext = path.extname(file.originalname).toLowerCase();
     
    9398    success: req.query.success || null,
    9499    maxBytesMb: Math.round(MAX_AUDIO_BYTES / 1024 / 1024),
     100    maxWavMb: Math.round(MAX_WAV_BYTES / 1024 / 1024),
    95101  });
    96102});
     
    119125      if (coverFile) try { fs.unlinkSync(coverFile.path); } catch {}
    120126      return fail(400, 'missing audio file');
     127    }
     128
     129    // Per-type audio size check. multer's globale limiet was de WAV-bovengrens
     130    // (100MB); gecomprimeerde formaten blijven op 50MB.
     131    const audioExt = path.extname(audioFile.originalname).toLowerCase();
     132    const audioLimit = audioByteLimitFor(audioExt);
     133    if (audioFile.size > audioLimit) {
     134      try { fs.unlinkSync(audioFile.path); } catch {}
     135      if (coverFile) try { fs.unlinkSync(coverFile.path); } catch {}
     136      return fail(400, `audio te groot (max ${Math.round(audioLimit / 1024 / 1024)}MB voor ${audioExt || 'dit type'})`);
    121137    }
    122138
  • src/views/pages/admin-audio.ejs

    r03af7f8 rfbc8628  
    4646        <span class="ax-dropzone-icon">🎵</span>
    4747        <strong class="ax-dropzone-title">Sleep audio hierheen</strong>
    48         <span class="ax-dropzone-sub">of klik om bestanden te kiezen<br><small>mp3, m4a, ogg, opus, flac, wav · max <%= maxBytesMb %> MB per bestand</small></span>
     48        <span class="ax-dropzone-sub">of klik om bestanden te kiezen<br><small>mp3, m4a, ogg, opus, flac · max <%= maxBytesMb %> MB · wav max <%= maxWavMb %> MB</small></span>
    4949        <input type="file" id="audio-files" accept="audio/*" multiple>
    5050      </label>
Note: See TracChangeset for help on using the changeset viewer.