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

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import * as path from 'path';
import * as fs from 'fs';
2022-04-05 01:37:31 +08:00
import { Config } from '../common/config/private/Config';
class ProjectPathClass {
public Root: string;
public ImageFolder: string;
2019-12-27 04:03:10 +08:00
public TempFolder: string;
public TranscodedFolder: string;
public FacesFolder: string;
2017-07-04 01:17:49 +08:00
public FrontendFolder: string;
2020-12-29 05:08:57 +08:00
public DBFolder: string;
constructor() {
this.reset();
}
normalizeRelative(pathStr: string): any {
return path.join(pathStr, path.sep);
}
2016-12-28 21:26:19 +08:00
2017-07-15 04:56:25 +08:00
getAbsolutePath(pathStr: string): string {
2019-12-10 18:25:26 +08:00
return path.isAbsolute(pathStr) ? pathStr : path.join(this.Root, pathStr);
2017-07-15 04:56:25 +08:00
}
getRelativePathToImages(pathStr: string): string {
return path.relative(this.ImageFolder, pathStr);
2017-07-19 16:21:52 +08:00
}
reset(): void {
2019-12-10 17:44:35 +08:00
this.Root = path.join(__dirname, '/../../');
2018-03-31 03:30:30 +08:00
this.FrontendFolder = path.join(this.Root, 'dist');
this.ImageFolder = this.getAbsolutePath(Config.Server.Media.folder);
2019-12-27 04:03:10 +08:00
this.TempFolder = this.getAbsolutePath(Config.Server.Media.tempFolder);
this.TranscodedFolder = path.join(this.TempFolder, 'tc');
this.FacesFolder = path.join(this.TempFolder, 'f');
2020-12-29 05:08:57 +08:00
this.DBFolder = this.getAbsolutePath(Config.Server.Database.dbFolder);
// create thumbnail folder if not exist
2019-12-27 04:03:10 +08:00
if (!fs.existsSync(this.TempFolder)) {
fs.mkdirSync(this.TempFolder);
}
}
}
export const ProjectPath = new ProjectPathClass();