1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/src/backend/ProjectPath.ts
2022-04-14 14:36:56 +02:00

47 lines
1.3 KiB
TypeScript

import * as path from 'path';
import * as fs from 'fs';
import { Config } from '../common/config/private/Config';
class ProjectPathClass {
public Root: string;
public ImageFolder: string;
public TempFolder: string;
public TranscodedFolder: string;
public FacesFolder: string;
public FrontendFolder: string;
public DBFolder: string;
constructor() {
this.reset();
}
normalizeRelative(pathStr: string): any {
return path.join(pathStr, path.sep);
}
getAbsolutePath(pathStr: string): string {
return path.isAbsolute(pathStr) ? pathStr : path.join(this.Root, pathStr);
}
getRelativePathToImages(pathStr: string): string {
return path.relative(this.ImageFolder, pathStr);
}
reset(): void {
this.Root = path.join(__dirname, '/../../');
this.FrontendFolder = path.join(this.Root, 'dist');
this.ImageFolder = this.getAbsolutePath(Config.Server.Media.folder);
this.TempFolder = this.getAbsolutePath(Config.Server.Media.tempFolder);
this.TranscodedFolder = path.join(this.TempFolder, 'tc');
this.FacesFolder = path.join(this.TempFolder, 'f');
this.DBFolder = this.getAbsolutePath(Config.Server.Database.dbFolder);
// create thumbnail folder if not exist
if (!fs.existsSync(this.TempFolder)) {
fs.mkdirSync(this.TempFolder);
}
}
}
export const ProjectPath = new ProjectPathClass();