fix: find renamed files by searching original Navidrome directory
When Navidrome has a stale index (e.g. file was renamed from
'01 - Idea 10.mp3' to '01 - Gibran Alcocer - Idea 10.mp3'),
_findFileInDir now falls back to the original file's directory
and matches by track-number prefix ('01 - ') so the renamed file
is found even without a Navidrome rescan.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
6fa9751fb6
commit
fce53e409d
1 file changed
+11
-8
@@ -697,9 +697,12 @@ app.get('/api/song-sorttags', async (req, res) => {
|
||||
} catch (e) { return res.status(502).json({ error: e.message }); }
|
||||
if (!path.isAbsolute(filePath)) filePath = path.join(CONFIG.musicPath, filePath);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
||||
const found = rebased || _findFileRecursive(CONFIG.musicPath, path.basename(filePath))
|
||||
|| _findFileInDir(path.dirname(rebased || path.join(CONFIG.musicPath, path.basename(filePath))), path.basename(filePath));
|
||||
const fileName = path.basename(filePath);
|
||||
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
||||
const rebasedDir = rebased ? path.dirname(rebased) : null;
|
||||
const found = rebased
|
||||
|| _findFileRecursive(CONFIG.musicPath, fileName)
|
||||
|| _findFileInDir(rebasedDir || path.dirname(filePath), fileName);
|
||||
if (found) filePath = found; else return res.status(404).json({ error: 'File not found' });
|
||||
}
|
||||
try {
|
||||
@@ -765,14 +768,14 @@ app.post('/api/edit-metadata', async (req, res) => {
|
||||
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
||||
const fileName = path.basename(filePath);
|
||||
const rebasedDir = rebased ? path.dirname(rebased) : null;
|
||||
// Also check the original dir — the file may have been renamed (e.g. artist added to filename)
|
||||
// but Navidrome's index is stale and still points to the old name.
|
||||
const originalDir = path.dirname(filePath);
|
||||
const found = rebased
|
||||
|| _findFileRecursive(CONFIG.musicPath, fileName)
|
||||
|| (rebasedDir && _findFileInDir(rebasedDir, fileName));
|
||||
|| _findFileInDir(rebasedDir || originalDir, fileName);
|
||||
if (found) { filePath = found; }
|
||||
else {
|
||||
console.warn(`[edit-metadata] File not found. nd_path=${filePath} music_root=${CONFIG.musicPath} rebased=${rebased}`);
|
||||
return res.status(404).json({ error: `File not found: ${filePath} (music root: ${CONFIG.musicPath})` });
|
||||
}
|
||||
else return res.status(404).json({ error: `File not found: ${filePath} (music root: ${CONFIG.musicPath})` });
|
||||
}
|
||||
|
||||
// Resolve artwork: base64 > URL
|
||||
|
||||
Reference in new issue
Block a user