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'; import {FileDTO} from '../../common/entities/FileDTO'; const LOG_TAG = '[DiskManager]'; export class DiskManager { static threadPool: DiskManagerTH = null; public static init() { if (Config.Server.Threading.enabled === true) { DiskManager.threadPool = new DiskManagerTH(1); } } public static async scanDirectoryNoMetadata(relativeDirectoryName: string, settings: DiskMangerWorker.DirectoryScanSettings = {}): Promise> { settings.noMetadata = true; return this.scanDirectory(relativeDirectoryName, settings); } public static async scanDirectory(relativeDirectoryName: string, settings: DiskMangerWorker.DirectoryScanSettings = {}): Promise { Logger.silly(LOG_TAG, 'scanning directory:', relativeDirectoryName); let directory: DirectoryDTO; if (Config.Server.Threading.enabled === true) { directory = await DiskManager.threadPool.execute(relativeDirectoryName, settings); } else { directory = await DiskMangerWorker.scanDirectory(relativeDirectoryName, settings); } DirectoryDTO.addReferences(directory); return directory; } }