fix(flac): set correct contentType for FLAC and other types in S3 sync; include contentType hint in stream endpoint response

This commit is contained in:
Geert Rademakes 2025-08-08 12:02:03 +02:00
parent dbf9dbcb8c
commit 5144df2e93
2 changed files with 21 additions and 4 deletions

View File

@ -209,6 +209,7 @@ router.get('/:id/stream', async (req, res) => {
res.json({
streamingUrl: presignedUrl,
musicFile,
contentType: musicFile.contentType || undefined,
});
} catch (error) {
console.error('Streaming error:', error);

View File

@ -171,6 +171,22 @@ class BackgroundJobService {
const audioMetadataService = new AudioMetadataService();
const songMatchingService = new SongMatchingService();
// Helper to set correct MIME type based on file extension
const guessContentType = (fileName: string): string => {
const ext = (fileName.split('.').pop() || '').toLowerCase();
switch (ext) {
case 'mp3': return 'audio/mpeg';
case 'wav': return 'audio/wav';
case 'flac': return 'audio/flac';
case 'm4a': return 'audio/mp4';
case 'aac': return 'audio/aac';
case 'ogg': return 'audio/ogg';
case 'opus': return 'audio/opus';
case 'wma': return 'audio/x-ms-wma';
default: return 'application/octet-stream';
}
};
// Phase 1: Quick filename matching
this.updateProgress(jobId, {
message: 'Phase 1: Fetching files from S3...',
@ -246,7 +262,7 @@ class BackgroundJobService {
originalName: filename,
s3Key: s3File.key,
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
contentType: 'audio/mpeg',
contentType: guessContentType(filename),
size: s3File.size,
...basicMetadata,
songId: matchedSong._id,
@ -323,7 +339,7 @@ class BackgroundJobService {
originalName: filename,
s3Key: s3File.key,
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
contentType: 'audio/mpeg',
contentType: guessContentType(filename),
size: s3File.size,
...metadata,
});