fix 无法修改配置文件

This commit is contained in:
SummerTail 2023-08-03 21:09:57 +08:00
parent e4151b94ed
commit da5dd7ebf9
3 changed files with 21 additions and 27 deletions

View File

@ -1,5 +1,5 @@
{
"downloadPath": "",
"vCookies": "b",
"vCookies": "e",
"torrentSavePath": ""
}

View File

@ -20,26 +20,20 @@ router.get('/getConfig', async (ctx) => {
/**
* 设置配置文件接口
*/
router.post('/setConfig', async (ctx) => {
let body = ctx.request.body;
console.info(body)
// if (body === "") {
// ctx.body = {
// code: -1,
// msg: "提交内容不能为空"
// }
// return
// }
//
// let b = config.setConfig(body);
// console.info(b)
// ctx.body = {
// code: b ? 0 : -1,
// msg: b ? 'ok' : "error",
// data: null
// }
router.post('/setConfig', async (req, res) => {
if (req.request.body === undefined) {
req.body = {
code: -1,
msg: "提交内容不能为空"
}
return
}
let b = config.setConfig(req.request.body);
req.body = {
code: b ? 0 : -2,
msg: b ? 'ok' : "error",
}
})
module.exports = router
module.exports = router

View File

@ -16,16 +16,16 @@ function getConfig() {
/**
* 保存配置文件
* @param string
* @param config{String}
* @return {boolean}
*/
function setConfig(string) {
console.info(string)
fs.writeFileSync("config.json", JSON.parse(string));
return getConfig() === string;
function setConfig(config) {
const data = JSON.stringify(config, null, 2)
fs.writeFileSync("config.json", data);
return JSON.stringify(getConfig(), null, 2) === data
}
module.exports = {
getConfig,
setConfig
}
}