diff --git a/backend/novasonic-server.js b/backend/novasonic-server.js index 348591b..b4d64b4 100644 --- a/backend/novasonic-server.js +++ b/backend/novasonic-server.js @@ -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