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() {
|
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;
|
||||||
},
|
},
|
||||||
|
@ -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}`);
|
||||||
}
|
*/
|
||||||
|
const pathsToInit = [
|
||||||
|
this.get('log'),
|
||||||
|
this.get('config'),
|
||||||
|
this.get('userData'),
|
||||||
|
this.get('media'),
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
pathsToInit.forEach((dirPath) => {
|
||||||
* 解析相对路径(基于项目根目录)
|
if (!fs.existsSync(dirPath)) {
|
||||||
* @param segments 路径片段
|
fc.createDir(dirPath);
|
||||||
*/
|
}
|
||||||
public resolve(...segments: string[]): string {
|
});
|
||||||
return path.join(this.baseDir, ...segments);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查路径是否存在(同步)
|
|
||||||
*/
|
|
||||||
public existsSync(targetPath: string): boolean {
|
|
||||||
try {
|
|
||||||
return fs.existsSync(targetPath);
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user