feat(server): first version
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const config = {
|
||||
dbFile: "./wxbot.db",
|
||||
dataDir: "./wxbot-data",
|
||||
mediaDir: "./wxbot-data/media",
|
||||
cacheDir: "./wxbot-data/cache",
|
||||
serve: true,
|
||||
httpHost: "127.0.0.1",
|
||||
httpPort: 9200,
|
||||
baseUrl: "http:127.0.0.1",
|
||||
debugMode: false,
|
||||
appCode: {},
|
||||
appAuthHash: {},
|
||||
};
|
||||
const globalData = {
|
||||
// 是否有旧的登录数据可重用
|
||||
hasSessionData: false,
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载配置文件
|
||||
* @param file {string}
|
||||
*/
|
||||
function loadConfig(file) {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(file, { encoding: "utf-8" }));
|
||||
Object.assign(config, data);
|
||||
if (!data.mediaDir) {
|
||||
config.mediaDir = path.join(config.dataDir, "media");
|
||||
}
|
||||
if (!data.cacheDir) {
|
||||
config.cacheDir = path.join(config.dataDir, "cache");
|
||||
}
|
||||
fs.mkdirSync(config.mediaDir, { recursive: true });
|
||||
fs.mkdirSync(config.cacheDir, { recursive: true });
|
||||
} catch (e) {
|
||||
throw Error("加载配置文件失败:" + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
globalData,
|
||||
config,
|
||||
loadConfig,
|
||||
};
|
||||
Reference in New Issue
Block a user