2016-05-26 03:58:56 +08:00
|
|
|
///<reference path="exif.d.ts"/>
|
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';
|
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
|
|
|
|
2017-07-04 16:24:20 +08:00
|
|
|
public static init() {
|
2018-05-13 00:19:51 +08:00
|
|
|
if (Config.Server.enableThreading === true) {
|
2017-07-04 16:24:20 +08:00
|
|
|
DiskManager.threadPool = new DiskManagerTH(1);
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2017-07-04 16:24:20 +08:00
|
|
|
public static async scanDirectory(relativeDirectoryName: string): Promise<DirectoryDTO> {
|
2018-03-31 03:30:30 +08:00
|
|
|
Logger.silly(LOG_TAG, 'scanning directory:', relativeDirectoryName);
|
2017-07-04 16:24:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
let directory: DirectoryDTO = null;
|
|
|
|
|
2018-05-13 00:19:51 +08:00
|
|
|
if (Config.Server.enableThreading === true) {
|
2017-07-04 16:24:20 +08:00
|
|
|
directory = await DiskManager.threadPool.execute(relativeDirectoryName);
|
|
|
|
} else {
|
|
|
|
directory = await DiskMangerWorker.scanDirectory(relativeDirectoryName);
|
|
|
|
}
|
2018-05-13 00:19:51 +08:00
|
|
|
const addDirs = (dir: DirectoryDTO) => {
|
2017-07-04 16:24:20 +08:00
|
|
|
dir.photos.forEach((ph) => {
|
|
|
|
ph.directory = dir;
|
|
|
|
});
|
|
|
|
dir.directories.forEach((d) => {
|
|
|
|
addDirs(d);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
addDirs(directory);
|
|
|
|
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
|
|
|
}
|