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

46 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';
2018-03-31 03:30:30 +08:00
import {Config} from '../common/config/private/Config';
class ProjectPathClass {
public Root: string;
public ImageFolder: string;
public ThumbnailFolder: string;
public TranscodedFolder: string;
public FacesFolder: string;
2017-07-04 01:17:49 +08:00
public FrontendFolder: string;
constructor() {
this.reset();
}
normalizeRelative(pathStr: string) {
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() {
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);
this.ThumbnailFolder = this.getAbsolutePath(Config.Server.Media.tempFolder);
this.TranscodedFolder = path.join(this.ThumbnailFolder, 'tc');
this.FacesFolder = path.join(this.ThumbnailFolder, 'f');
// create thumbnail folder if not exist
if (!fs.existsSync(this.ThumbnailFolder)) {
fs.mkdirSync(this.ThumbnailFolder);
}
}
}
export const ProjectPath = new ProjectPathClass();