fix(config): improve auto-link UX; fix song update in background job; upsert MusicFile on complex matching

This commit is contained in:
Geert Rademakes 2025-08-13 16:54:38 +02:00
parent fe3a7abf32
commit d87d83eaf6
2 changed files with 21 additions and 19 deletions

View File

@ -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
}
}
}

View File

@ -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,