ptSend/util/config/config.js

32 lines
612 B
JavaScript
Raw Normal View History

2023-08-01 13:02:12 +08:00
"use strict";
const fs = require("fs");
const {cwd} = require("process");
const path = require('path');
let configPath = path.join(cwd(), "/config.json");
/**
* 获取配置文件
* @returns {JSON}
*/
function getConfig() {
let file = fs.readFileSync(configPath);
return JSON.parse(file);
}
/**
* 保存配置文件
2023-08-03 21:09:57 +08:00
* @param config{String}
2023-08-01 13:02:12 +08:00
* @return {boolean}
*/
2023-08-03 21:09:57 +08:00
function setConfig(config) {
const data = JSON.stringify(config, null, 2)
fs.writeFileSync("config.json", data);
return JSON.stringify(getConfig(), null, 2) === data
2023-08-01 13:02:12 +08:00
}
module.exports = {
getConfig,
setConfig
2023-08-03 21:09:57 +08:00
}