Fix library path saving - auto-create directory and improve error handling
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user