Fix library path saving - auto-create directory and improve error handling
This commit is contained in:
@@ -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