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

View File

@ -11,22 +11,35 @@ router.get('/getConfig', async (ctx) => {
let json = config.getConfig();
const b = json === '{}'
return {
ctx.body = {
code: b ? -1 : 0,
msg: b ? 'ok' : "error",
msg: b ? 'error' : "ok",
data: json
}
})
/**
* 设置配置文件接口
*/
router.get('/setConfig', async (ctx) => {
let b = config.setConfig(ctx.data);
return {
code: b ? -1 : 0,
msg: b ? 'ok' : "error",
data: null
}
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
// }
})
module.exports = router

View File

@ -16,11 +16,12 @@ function getConfig() {
/**
* 保存配置文件
* @param string {JSON}
* @param string
* @return {boolean}
*/
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;
}