mirror of
https://github.com/crystelf/crystelf-core.git
synced 2025-07-04 14:49:19 +00:00
优化path
This commit is contained in:
parent
964cc48993
commit
f0c3adbd38
@ -13,6 +13,7 @@ const apps = {
|
||||
async createApp() {
|
||||
const app = express();
|
||||
|
||||
paths.init();
|
||||
logger.info('晶灵核心初始化..');
|
||||
app.use(express.json());
|
||||
app.use(compression());
|
||||
@ -44,7 +45,6 @@ const apps = {
|
||||
});
|
||||
}
|
||||
});
|
||||
paths.init();
|
||||
logger.info('晶灵核心初始化完毕!');
|
||||
return app;
|
||||
},
|
||||
|
@ -1,7 +1,6 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import fc from './file';
|
||||
import logger from './logger';
|
||||
|
||||
class PathManager {
|
||||
private static instance: PathManager;
|
||||
@ -45,6 +44,7 @@ class PathManager {
|
||||
* 初始化
|
||||
*/
|
||||
public init(): void {
|
||||
/*
|
||||
const logPath = this.get('log');
|
||||
const imagePath = this.get('images');
|
||||
const dataPath = this.get('userData');
|
||||
@ -56,25 +56,19 @@ class PathManager {
|
||||
logger.debug(`日志目录初始化: ${logPath}`);
|
||||
logger.debug(`图像目录初始化: ${imagePath};${mediaPath}`);
|
||||
logger.debug(`用户数据目录初始化: ${dataPath}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析相对路径(基于项目根目录)
|
||||
* @param segments 路径片段
|
||||
*/
|
||||
public resolve(...segments: string[]): string {
|
||||
return path.join(this.baseDir, ...segments);
|
||||
}
|
||||
const pathsToInit = [
|
||||
this.get('log'),
|
||||
this.get('config'),
|
||||
this.get('userData'),
|
||||
this.get('media'),
|
||||
];
|
||||
|
||||
/**
|
||||
* 检查路径是否存在(同步)
|
||||
*/
|
||||
public existsSync(targetPath: string): boolean {
|
||||
try {
|
||||
return fs.existsSync(targetPath);
|
||||
} catch {
|
||||
return false;
|
||||
pathsToInit.forEach((dirPath) => {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fc.createDir(dirPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user