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

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-05-26 03:58:56 +08:00
///<reference path="exif.d.ts"/>
2016-12-28 03:55:51 +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
const LOG_TAG = "[DiskManager]";
export class DiskManager {
static threadPool: DiskManagerTH = null;
public static init() {
if (Config.Server.enableThreading == true) {
DiskManager.threadPool = new DiskManagerTH(1);
}
}
public static async scanDirectory(relativeDirectoryName: string): Promise<DirectoryDTO> {
Logger.silly(LOG_TAG, "scanning directory:", relativeDirectoryName);
let directory: DirectoryDTO = null;
if (Config.Server.enableThreading == true) {
directory = await DiskManager.threadPool.execute(relativeDirectoryName);
} else {
directory = await DiskMangerWorker.scanDirectory(relativeDirectoryName);
}
let addDirs = (dir: DirectoryDTO) => {
dir.photos.forEach((ph) => {
ph.directory = dir;
});
dir.directories.forEach((d) => {
addDirs(d);
});
};
addDirs(directory);
return directory;
}
2017-06-05 00:45:29 +08:00
}