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

@@ -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}`
});
}
}