fix 配置接口请求失效
This commit is contained in:
		
							parent
							
								
									a0d7b9b17f
								
							
						
					
					
						commit
						e4151b94ed
					
				@ -1,5 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "downloadPath": "",
 | 
			
		||||
  "vCookies": "",
 | 
			
		||||
  "vCookies": "b",
 | 
			
		||||
  "torrentSavePath": ""
 | 
			
		||||
}
 | 
			
		||||
@ -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
 | 
			
		||||
@ -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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user