Fix library path saving - auto-create directory and improve error handling

This commit is contained in:
2025-12-07 22:41:09 +00:00
parent 1392bc9f12
commit 427f229d69
2 changed files with 15 additions and 7 deletions

View File

@@ -311,7 +311,7 @@ async function loadSettings() {
// Save library path // Save library path
async function saveLibraryPath() { async function saveLibraryPath() {
const libraryPath = document.getElementById('libraryPath').value; const libraryPath = document.getElementById('libraryPath').value.trim();
if (!libraryPath) { if (!libraryPath) {
alert('Please enter a library path'); alert('Please enter a library path');
@@ -328,13 +328,14 @@ async function saveLibraryPath() {
const data = await res.json(); const data = await res.json();
if (res.ok) { 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 { } else {
alert(`Error: ${data.error}`); alert('❌ Error: ' + (data.error || 'Failed to save'));
console.error('Server error:', data);
} }
} catch (error) { } catch (error) {
console.error('Error saving settings:', 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);
} }
} }

View File

@@ -44,12 +44,19 @@ router.patch('/', async (req, res) => {
const { libraryPath } = req.body; const { libraryPath } = req.body;
if (libraryPath) { 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 { try {
await fs.access(libraryPath); await fs.mkdir(resolvedPath, { recursive: true });
config.libraryPath = libraryPath; config.libraryPath = libraryPath;
} catch (error) { } 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}`
});
} }
} }