优化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() { async createApp() {
const app = express(); const app = express();
paths.init();
logger.info('晶灵核心初始化..'); logger.info('晶灵核心初始化..');
app.use(express.json()); app.use(express.json());
app.use(compression()); app.use(compression());
@ -44,7 +45,6 @@ const apps = {
}); });
} }
}); });
paths.init();
logger.info('晶灵核心初始化完毕!'); logger.info('晶灵核心初始化完毕!');
return app; return app;
}, },

View File

@ -1,7 +1,6 @@
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import fc from './file'; import fc from './file';
import logger from './logger';
class PathManager { class PathManager {
private static instance: PathManager; private static instance: PathManager;
@ -45,6 +44,7 @@ class PathManager {
* *
*/ */
public init(): void { public init(): void {
/*
const logPath = this.get('log'); const logPath = this.get('log');
const imagePath = this.get('images'); const imagePath = this.get('images');
const dataPath = this.get('userData'); const dataPath = this.get('userData');
@ -56,25 +56,19 @@ class PathManager {
logger.debug(`日志目录初始化: ${logPath}`); logger.debug(`日志目录初始化: ${logPath}`);
logger.debug(`图像目录初始化: ${imagePath};${mediaPath}`); logger.debug(`图像目录初始化: ${imagePath};${mediaPath}`);
logger.debug(`用户数据目录初始化: ${dataPath}`); logger.debug(`用户数据目录初始化: ${dataPath}`);
}
/**
*
* @param segments
*/ */
public resolve(...segments: string[]): string { const pathsToInit = [
return path.join(this.baseDir, ...segments); this.get('log'),
} this.get('config'),
this.get('userData'),
this.get('media'),
];
/** pathsToInit.forEach((dirPath) => {
* if (!fs.existsSync(dirPath)) {
*/ fc.createDir(dirPath);
public existsSync(targetPath: string): boolean {
try {
return fs.existsSync(targetPath);
} catch {
return false;
} }
});
} }
} }