1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/DiskManger.ts
Patrik J. Braun f8a361cb9e implementing video converting task
note: braking changes in database and config file
2019-12-09 14:05:06 +01:00

44 lines
1.3 KiB
TypeScript

import {DirectoryDTO} from '../../common/entities/DirectoryDTO';
import {Logger} from '../Logger';
import {Config} from '../../common/config/private/Config';
import {DiskManagerTH} from './threading/ThreadPool';
import {DiskMangerWorker} from './threading/DiskMangerWorker';
const LOG_TAG = '[DiskManager]';
export class DiskManager {
static threadPool: DiskManagerTH = null;
public static init() {
if (Config.Server.Threading.enable === true) {
DiskManager.threadPool = new DiskManagerTH(1);
}
}
public static async scanDirectory(relativeDirectoryName: string,
settings: DiskMangerWorker.DirectoryScanSettings = {}): Promise<DirectoryDTO> {
Logger.silly(LOG_TAG, 'scanning directory:', relativeDirectoryName);
let directory: DirectoryDTO;
if (Config.Server.Threading.enable === true) {
directory = await DiskManager.threadPool.execute(relativeDirectoryName, settings);
} else {
directory = await DiskMangerWorker.scanDirectory(relativeDirectoryName, settings);
}
const addDirs = (dir: DirectoryDTO) => {
dir.media.forEach((ph) => {
ph.directory = dir;
});
dir.directories.forEach((d) => {
addDirs(d);
});
};
addDirs(directory);
return directory;
}
}