优化path

This commit is contained in:
Jerry 2025-04-30 13:08:51 +08:00
parent 964cc48993
commit f0c3adbd38
2 changed files with 14 additions and 20 deletions

View File

@ -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;
},

View File

@ -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}`);
}
*/
const pathsToInit = [
this.get('log'),
this.get('config'),
this.get('userData'),
this.get('media'),
];
/**
*
* @param segments
*/
public resolve(...segments: string[]): string {
return path.join(this.baseDir, ...segments);
}
/**
*
*/
public existsSync(targetPath: string): boolean {
try {
return fs.existsSync(targetPath);
} catch {
return false;
}
pathsToInit.forEach((dirPath) => {
if (!fs.existsSync(dirPath)) {
fc.createDir(dirPath);
}
});
}
}