fix 配置接口请求失效

This commit is contained in:
SummerTail 2023-08-01 14:18:44 +08:00
parent a0d7b9b17f
commit e4151b94ed
3 changed files with 26 additions and 12 deletions

View File

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

View File

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

View File

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