2021-04-18 21:48:35 +08:00
|
|
|
import {DirectoryDTO, DirectoryDTOUtils} from '../../common/entities/DirectoryDTO';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {Logger} from '../Logger';
|
|
|
|
import {Config} from '../../common/config/private/Config';
|
|
|
|
import {DiskManagerTH} from './threading/ThreadPool';
|
2021-04-18 21:48:35 +08:00
|
|
|
import {DirectoryScanSettings, DiskMangerWorker} from './threading/DiskMangerWorker';
|
2019-12-31 18:12:59 +08:00
|
|
|
import {FileDTO} from '../../common/entities/FileDTO';
|
2016-03-20 02:59:19 +08:00
|
|
|
|
2017-06-04 04:35:47 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
const LOG_TAG = '[DiskManager]';
|
|
|
|
|
2017-01-23 03:30:23 +08:00
|
|
|
export class DiskManager {
|
2017-07-04 16:24:20 +08:00
|
|
|
static threadPool: DiskManagerTH = null;
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static init(): void {
|
2019-12-15 21:40:31 +08:00
|
|
|
if (Config.Server.Threading.enabled === true) {
|
2017-07-04 16:24:20 +08:00
|
|
|
DiskManager.threadPool = new DiskManagerTH(1);
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2019-12-31 18:12:59 +08:00
|
|
|
|
|
|
|
public static async scanDirectoryNoMetadata(relativeDirectoryName: string,
|
2021-04-18 21:48:35 +08:00
|
|
|
settings: DirectoryScanSettings = {}): Promise<DirectoryDTO<FileDTO>> {
|
2019-12-31 18:12:59 +08:00
|
|
|
settings.noMetadata = true;
|
|
|
|
return this.scanDirectory(relativeDirectoryName, settings);
|
|
|
|
}
|
|
|
|
|
2019-12-09 21:05:06 +08:00
|
|
|
public static async scanDirectory(relativeDirectoryName: string,
|
2021-04-18 21:48:35 +08:00
|
|
|
settings: DirectoryScanSettings = {}): Promise<DirectoryDTO> {
|
2017-07-04 16:24:20 +08:00
|
|
|
|
2019-12-09 21:05:06 +08:00
|
|
|
Logger.silly(LOG_TAG, 'scanning directory:', relativeDirectoryName);
|
2017-07-04 16:24:20 +08:00
|
|
|
|
2019-12-09 21:05:06 +08:00
|
|
|
let directory: DirectoryDTO;
|
2017-07-04 16:24:20 +08:00
|
|
|
|
2019-12-15 21:40:31 +08:00
|
|
|
if (Config.Server.Threading.enabled === true) {
|
2019-12-09 21:05:06 +08:00
|
|
|
directory = await DiskManager.threadPool.execute(relativeDirectoryName, settings);
|
2017-07-04 16:24:20 +08:00
|
|
|
} else {
|
2019-12-09 21:05:06 +08:00
|
|
|
directory = await DiskMangerWorker.scanDirectory(relativeDirectoryName, settings);
|
2017-07-04 16:24:20 +08:00
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
DirectoryDTOUtils.unpackDirectory(directory);
|
2017-07-04 16:24:20 +08:00
|
|
|
return directory;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2017-01-23 03:30:23 +08:00
|
|
|
|
2017-06-05 00:45:29 +08:00
|
|
|
}
|