1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/src/backend/model/DiskManger.ts

44 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
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';
2019-12-31 18:12:59 +08:00
import {FileDTO} from '../../common/entities/FileDTO';
2016-03-20 02:59:19 +08:00
2018-03-31 03:30:30 +08:00
const LOG_TAG = '[DiskManager]';
export class DiskManager {
static threadPool: DiskManagerTH = null;
public static init() {
2019-12-15 21:40:31 +08:00
if (Config.Server.Threading.enabled === true) {
DiskManager.threadPool = new DiskManagerTH(1);
}
}
2019-12-31 18:12:59 +08:00
public static async scanDirectoryNoMetadata(relativeDirectoryName: string,
settings: DiskMangerWorker.DirectoryScanSettings = {}): Promise<DirectoryDTO<FileDTO>> {
settings.noMetadata = true;
return this.scanDirectory(relativeDirectoryName, settings);
}
public static async scanDirectory(relativeDirectoryName: string,
settings: DiskMangerWorker.DirectoryScanSettings = {}): Promise<DirectoryDTO> {
Logger.silly(LOG_TAG, 'scanning directory:', relativeDirectoryName);
let directory: DirectoryDTO;
2019-12-15 21:40:31 +08:00
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;
}
2017-06-05 00:45:29 +08:00
}