2018-03-31 03:30:30 +08:00
|
|
|
import * as path from 'path';
|
2019-12-09 21:05:06 +08:00
|
|
|
import * as fs from 'fs';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {Config} from '../common/config/private/Config';
|
2016-06-22 22:34:44 +08:00
|
|
|
|
|
|
|
class ProjectPathClass {
|
2017-06-11 04:32:56 +08:00
|
|
|
public Root: string;
|
|
|
|
public ImageFolder: string;
|
|
|
|
public ThumbnailFolder: string;
|
2019-12-09 21:05:06 +08:00
|
|
|
public TranscendedFolder: string;
|
2017-07-04 01:17:49 +08:00
|
|
|
public FrontendFolder: string;
|
2016-06-22 22:34:44 +08:00
|
|
|
|
2019-12-09 21:05:06 +08:00
|
|
|
constructor() {
|
|
|
|
this.reset();
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-12-09 21:05:06 +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, '/../../');
|
2017-07-15 04:56:25 +08:00
|
|
|
this.ImageFolder = this.getAbsolutePath(Config.Server.imagesFolder);
|
2019-12-09 21:05:06 +08:00
|
|
|
this.ThumbnailFolder = this.getAbsolutePath(Config.Server.Thumbnail.folder);
|
|
|
|
this.TranscendedFolder = path.join(this.ThumbnailFolder, 'tc');
|
2018-03-31 03:30:30 +08:00
|
|
|
this.FrontendFolder = path.join(this.Root, 'dist');
|
2019-12-09 21:05:06 +08:00
|
|
|
|
|
|
|
// create thumbnail folder if not exist
|
|
|
|
if (!fs.existsSync(this.ThumbnailFolder)) {
|
|
|
|
fs.mkdirSync(this.ThumbnailFolder);
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-06-22 22:34:44 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
export const ProjectPath = new ProjectPathClass();
|