fix(matching): URL-decode filenames and Rekordbox locations during quick match and location matching (%20, %27 etc.)

This commit is contained in:
Geert Rademakes 2025-08-08 11:00:08 +02:00
parent fe282bf34f
commit 07044c7594
2 changed files with 8 additions and 4 deletions

View File

@ -222,13 +222,15 @@ class BackgroundJobService {
}); });
// Quick filename matching logic // Quick filename matching logic
const normalizedS3Filename = filename.replace(/\.[^/.]+$/, '').toLowerCase(); // Decode URL-encoded sequences so %20, %27 etc. are compared correctly
const safeDecode = (s: string): string => { try { return decodeURIComponent(s); } catch { return s; } };
const normalizedS3Filename = safeDecode(filename).replace(/\.[^/.]+$/, '').toLowerCase();
let matchedSong = null; let matchedSong = null;
for (const song of allSongs) { for (const song of allSongs) {
if (song.location) { if (song.location) {
const rekordboxFilename = song.location.split(/[/\\]/).pop() || song.location; const rekordboxFilename = song.location.split(/[/\\]/).pop() || song.location;
const normalizedRekordboxFilename = rekordboxFilename.replace(/\.[^/.]+$/, '').toLowerCase(); const normalizedRekordboxFilename = safeDecode(rekordboxFilename).replace(/\.[^/.]+$/, '').toLowerCase();
if (normalizedS3Filename === normalizedRekordboxFilename) { if (normalizedS3Filename === normalizedRekordboxFilename) {
matchedSong = song; matchedSong = song;

View File

@ -487,8 +487,10 @@ export class SongMatchingService {
private matchLocation(filename: string, location: string): { score: number; reason: string } { private matchLocation(filename: string, location: string): { score: number; reason: string } {
if (!filename || !location) return { score: 0, reason: '' }; if (!filename || !location) return { score: 0, reason: '' };
const cleanFilename = this.cleanString(filename); // Decode URL-encoded sequences so Rekordbox paths with %20 etc. match S3 keys correctly
const cleanLocation = this.cleanString(location); const safeDecode = (s: string): string => { try { return decodeURIComponent(s); } catch { return s; } };
const cleanFilename = this.cleanString(safeDecode(filename));
const cleanLocation = this.cleanString(safeDecode(location));
// Extract filename from location path (handle different path separators) // Extract filename from location path (handle different path separators)
const pathParts = cleanLocation.split(/[\/\\]/); const pathParts = cleanLocation.split(/[\/\\]/);