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

@ -573,11 +573,12 @@ class BackgroundJobService {
updateOne: { updateOne: {
filter: { _id: bestMatch.song._id }, filter: { _id: bestMatch.song._id },
update: { update: {
$addToSet: { $set: {
s3File: { 's3File.musicFileId': musicFile._id,
musicFileId: musicFile._id, 's3File.s3Key': musicFile.s3Key,
hasS3File: true '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) { if (!response.ok) {
const result = await response.json(); const errText = await response.text();
toast({ throw new Error(errText || 'Auto-linking failed');
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');
} }
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) { } catch (error) {
console.error('Error during auto-linking:', error); console.error('Error during auto-linking:', error);
toast({ toast({
title: 'Error', title: 'Error',
description: 'Failed to auto-link music files', description: error instanceof Error ? error.message : 'Failed to auto-link music files',
status: 'error', status: 'error',
duration: 3000, duration: 3000,
isClosable: true, isClosable: true,