From 427f229d6992211703ba1fc82da91f37df4dc402 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Sun, 7 Dec 2025 22:41:09 +0000 Subject: [PATCH] Fix library path saving - auto-create directory and improve error handling --- public/app.js | 9 +++++---- src/routes/settings.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/public/app.js b/public/app.js index d4a1e7d..1ff8875 100644 --- a/public/app.js +++ b/public/app.js @@ -311,7 +311,7 @@ async function loadSettings() { // Save library path async function saveLibraryPath() { - const libraryPath = document.getElementById('libraryPath').value; + const libraryPath = document.getElementById('libraryPath').value.trim(); if (!libraryPath) { alert('Please enter a library path'); @@ -328,13 +328,14 @@ async function saveLibraryPath() { const data = await res.json(); if (res.ok) { - alert('Library path updated! Please restart the server for changes to take effect.'); + alert('✅ Library path saved!\n\nPath: ' + libraryPath + '\n\nPlease restart the server for changes to take effect.'); } else { - alert(`Error: ${data.error}`); + alert('❌ Error: ' + (data.error || 'Failed to save')); + console.error('Server error:', data); } } catch (error) { console.error('Error saving settings:', error); - alert('Failed to save settings'); + alert('❌ Failed to save settings. Check console for details.\n\nError: ' + error.message); } } diff --git a/src/routes/settings.js b/src/routes/settings.js index 4c6d469..4386ec1 100644 --- a/src/routes/settings.js +++ b/src/routes/settings.js @@ -44,12 +44,19 @@ router.patch('/', async (req, res) => { const { libraryPath } = req.body; if (libraryPath) { - // Validate path exists + // Resolve path (handle relative paths) + const resolvedPath = path.isAbsolute(libraryPath) + ? libraryPath + : path.join(process.cwd(), libraryPath); + + // Try to create directory if it doesn't exist try { - await fs.access(libraryPath); + await fs.mkdir(resolvedPath, { recursive: true }); config.libraryPath = libraryPath; } catch (error) { - return res.status(400).json({ error: 'Library path does not exist' }); + return res.status(400).json({ + error: `Cannot create or access path: ${error.message}` + }); } }