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": "", "downloadPath": "",
"vCookies": "b", "vCookies": "e",
"torrentSavePath": "" "torrentSavePath": ""
} }

View File

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