diff --git a/packages/backend/src/services/backgroundJobService.ts b/packages/backend/src/services/backgroundJobService.ts index 77a419e..79cdc2b 100644 --- a/packages/backend/src/services/backgroundJobService.ts +++ b/packages/backend/src/services/backgroundJobService.ts @@ -572,12 +572,13 @@ class BackgroundJobService { songUpdates.push({ updateOne: { filter: { _id: bestMatch.song._id }, - update: { - $addToSet: { - s3File: { - musicFileId: musicFile._id, - hasS3File: true - } + update: { + $set: { + 's3File.musicFileId': musicFile._id, + 's3File.s3Key': musicFile.s3Key, + 's3File.s3Url': musicFile.s3Url, + 's3File.streamingUrl': musicFile.s3Key ? `${process.env.S3_ENDPOINT}/${process.env.S3_BUCKET_NAME}/${musicFile.s3Key}` : undefined, + 's3File.hasS3File': true } } } diff --git a/packages/frontend/src/components/SongMatching.tsx b/packages/frontend/src/components/SongMatching.tsx index 7fb7dbc..d33e28d 100644 --- a/packages/frontend/src/components/SongMatching.tsx +++ b/packages/frontend/src/components/SongMatching.tsx @@ -114,24 +114,25 @@ export const SongMatching: React.FC = () => { }), }); - if (response.ok) { - const result = await response.json(); - toast({ - title: 'Auto-linking Complete', - description: `Linked ${result.result.linked} files, ${result.result.unmatched} unmatched`, - status: 'success', - duration: 5000, - isClosable: true, - }); - loadData(); // Refresh data - } else { - throw new Error('Auto-linking failed'); + if (!response.ok) { + const errText = await response.text(); + throw new Error(errText || 'Auto-linking failed'); } + + const result = await response.json(); + toast({ + title: 'Auto-linking Started', + description: `Job ${result.jobId} started.`, + status: 'info', + duration: 4000, + isClosable: true, + }); + // Do not call loadData immediately; background job UI will refresh stats as it completes } catch (error) { console.error('Error during auto-linking:', error); toast({ title: 'Error', - description: 'Failed to auto-link music files', + description: error instanceof Error ? error.message : 'Failed to auto-link music files', status: 'error', duration: 3000, isClosable: true,