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:
parent
dbf9dbcb8c
commit
5144df2e93
@ -208,7 +208,8 @@ router.get('/:id/stream', async (req, res) => {
|
||||
|
||||
res.json({
|
||||
streamingUrl: presignedUrl,
|
||||
musicFile,
|
||||
musicFile,
|
||||
contentType: musicFile.contentType || undefined,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Streaming error:', error);
|
||||
|
||||
@ -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...',
|
||||
@ -240,13 +256,13 @@ class BackgroundJobService {
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedSong) {
|
||||
if (matchedSong) {
|
||||
const basicMetadata = audioMetadataService.extractBasicMetadataFromFilename(filename);
|
||||
const musicFile = new MusicFile({
|
||||
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,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user