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
+10
-7
@@ -697,9 +697,12 @@ app.get('/api/song-sorttags', async (req, res) => {
|
|||||||
} catch (e) { return res.status(502).json({ error: e.message }); }
|
} catch (e) { return res.status(502).json({ error: e.message }); }
|
||||||
if (!path.isAbsolute(filePath)) filePath = path.join(CONFIG.musicPath, filePath);
|
if (!path.isAbsolute(filePath)) filePath = path.join(CONFIG.musicPath, filePath);
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
|
const fileName = path.basename(filePath);
|
||||||
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
||||||
const found = rebased || _findFileRecursive(CONFIG.musicPath, path.basename(filePath))
|
const rebasedDir = rebased ? path.dirname(rebased) : null;
|
||||||
|| _findFileInDir(path.dirname(rebased || path.join(CONFIG.musicPath, path.basename(filePath))), path.basename(filePath));
|
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' });
|
if (found) filePath = found; else return res.status(404).json({ error: 'File not found' });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -765,14 +768,14 @@ app.post('/api/edit-metadata', async (req, res) => {
|
|||||||
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
const rebased = _rebasePath(filePath, CONFIG.musicPath);
|
||||||
const fileName = path.basename(filePath);
|
const fileName = path.basename(filePath);
|
||||||
const rebasedDir = rebased ? path.dirname(rebased) : null;
|
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
|
const found = rebased
|
||||||
|| _findFileRecursive(CONFIG.musicPath, fileName)
|
|| _findFileRecursive(CONFIG.musicPath, fileName)
|
||||||
|| (rebasedDir && _findFileInDir(rebasedDir, fileName));
|
|| _findFileInDir(rebasedDir || originalDir, fileName);
|
||||||
if (found) { filePath = found; }
|
if (found) { filePath = found; }
|
||||||
else {
|
else return res.status(404).json({ error: `File not found: ${filePath} (music root: ${CONFIG.musicPath})` });
|
||||||
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})` });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve artwork: base64 > URL
|
// Resolve artwork: base64 > URL
|
||||||
|
|||||||
Reference in new issue
Block a user