mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 12:50:09 +00:00
Fix file copy location to respect configured media directory
Previously, files were always being copied to /media/audiobooks regardless of the configured media directory in settings. This was caused by: 1. FileOrganizer singleton reading from MEDIA_DIR env var (never set) instead of database config 'media_dir' 2. Hardcoded /media/audiobooks fallback being used when env var not found 3. Three locations passing hardcoded paths to addOrganizeJob (unused) Changes: - Modified getFileOrganizer() to read media_dir from database config - Made targetPath parameter optional in addOrganizeJob (not used by processor) - Removed hardcoded /media/audiobooks paths from all addOrganizeJob calls - Updated organize-files processor to await getFileOrganizer() - Updated documentation to reflect configuration behavior Files now correctly copy to the directory configured in setup wizard or settings page, with /media/audiobooks only as fallback if not configured. Fixes: User-reported issue where configured media directory was ignored
This commit is contained in:
@@ -464,16 +464,18 @@ export class FileOrganizer {
|
||||
}
|
||||
}
|
||||
|
||||
// Singleton instance
|
||||
let fileOrganizer: FileOrganizer | null = null;
|
||||
/**
|
||||
* Get FileOrganizer instance configured from database settings
|
||||
* Reads media_dir from database configuration, falls back to /media/audiobooks if not configured
|
||||
*/
|
||||
export async function getFileOrganizer(): Promise<FileOrganizer> {
|
||||
// Read media_dir from database config
|
||||
const config = await prisma.configuration.findUnique({
|
||||
where: { key: 'media_dir' },
|
||||
});
|
||||
|
||||
export function getFileOrganizer(): FileOrganizer {
|
||||
if (!fileOrganizer) {
|
||||
const mediaDir = process.env.MEDIA_DIR || '/media/audiobooks';
|
||||
const tempDir = process.env.TEMP_DIR || '/tmp/readmeabook';
|
||||
const mediaDir = config?.value || process.env.MEDIA_DIR || '/media/audiobooks';
|
||||
const tempDir = process.env.TEMP_DIR || '/tmp/readmeabook';
|
||||
|
||||
fileOrganizer = new FileOrganizer(mediaDir, tempDir);
|
||||
}
|
||||
|
||||
return fileOrganizer;
|
||||
return new FileOrganizer(mediaDir, tempDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user