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({
|
res.json({
|
||||||
streamingUrl: presignedUrl,
|
streamingUrl: presignedUrl,
|
||||||
musicFile,
|
musicFile,
|
||||||
|
contentType: musicFile.contentType || undefined,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Streaming error:', error);
|
console.error('Streaming error:', error);
|
||||||
|
|||||||
@ -170,6 +170,22 @@ class BackgroundJobService {
|
|||||||
const s3Service = await S3Service.createFromConfig();
|
const s3Service = await S3Service.createFromConfig();
|
||||||
const audioMetadataService = new AudioMetadataService();
|
const audioMetadataService = new AudioMetadataService();
|
||||||
const songMatchingService = new SongMatchingService();
|
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
|
// Phase 1: Quick filename matching
|
||||||
this.updateProgress(jobId, {
|
this.updateProgress(jobId, {
|
||||||
@ -240,13 +256,13 @@ class BackgroundJobService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchedSong) {
|
if (matchedSong) {
|
||||||
const basicMetadata = audioMetadataService.extractBasicMetadataFromFilename(filename);
|
const basicMetadata = audioMetadataService.extractBasicMetadataFromFilename(filename);
|
||||||
const musicFile = new MusicFile({
|
const musicFile = new MusicFile({
|
||||||
originalName: filename,
|
originalName: filename,
|
||||||
s3Key: s3File.key,
|
s3Key: s3File.key,
|
||||||
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
|
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
|
||||||
contentType: 'audio/mpeg',
|
contentType: guessContentType(filename),
|
||||||
size: s3File.size,
|
size: s3File.size,
|
||||||
...basicMetadata,
|
...basicMetadata,
|
||||||
songId: matchedSong._id,
|
songId: matchedSong._id,
|
||||||
@ -323,7 +339,7 @@ class BackgroundJobService {
|
|||||||
originalName: filename,
|
originalName: filename,
|
||||||
s3Key: s3File.key,
|
s3Key: s3File.key,
|
||||||
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
|
s3Url: `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${s3File.key}`,
|
||||||
contentType: 'audio/mpeg',
|
contentType: guessContentType(filename),
|
||||||
size: s3File.size,
|
size: s3File.size,
|
||||||
...metadata,
|
...metadata,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user