2016-05-25 21:58:56 +02:00
|
|
|
///<reference path="exif.d.ts"/>
|
2016-12-27 20:55:51 +01:00
|
|
|
import {DirectoryDTO} from "../../common/entities/DirectoryDTO";
|
2017-06-03 22:35:47 +02:00
|
|
|
import {Logger} from "../Logger";
|
2017-06-10 22:32:56 +02:00
|
|
|
import {Config} from "../../common/config/private/Config";
|
2017-07-04 10:24:20 +02:00
|
|
|
import {DiskManagerTH} from "./threading/ThreadPool";
|
|
|
|
import {DiskMangerWorker} from "./threading/DiskMangerWorker";
|
2016-03-19 19:59:19 +01:00
|
|
|
|
2017-06-03 22:35:47 +02:00
|
|
|
|
|
|
|
const LOG_TAG = "[DiskManager]";
|
|
|
|
|
2017-01-22 20:30:23 +01:00
|
|
|
|
|
|
|
export class DiskManager {
|
2017-07-04 10:24:20 +02:00
|
|
|
static threadPool: DiskManagerTH = null;
|
2017-06-10 22:32:56 +02:00
|
|
|
|
2017-07-04 10:24:20 +02:00
|
|
|
public static init() {
|
|
|
|
if (Config.Server.enableThreading == true) {
|
|
|
|
DiskManager.threadPool = new DiskManagerTH(1);
|
|
|
|
}
|
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
|
2017-07-04 10:24:20 +02:00
|
|
|
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-10 22:32:56 +02:00
|
|
|
}
|
2017-01-22 20:30:23 +01:00
|
|
|
|
2017-06-04 18:45:29 +02:00
|
|
|
}
|