ptSend/router/config.js

44 lines
831 B
JavaScript
Raw Normal View History

2023-08-03 21:41:18 +08:00
/*
配置文件获取修改接口
*/
2023-08-01 13:02:12 +08:00
const Router = require("koa-router")
const config = require("../util/config/config")
const router = new Router({
prefix: "/config"
})
/**
* 获取配置文件接口
*/
router.get('/getConfig', async (ctx) => {
let json = config.getConfig();
const b = json === '{}'
2023-08-01 14:18:44 +08:00
ctx.body = {
2023-08-01 13:02:12 +08:00
code: b ? -1 : 0,
2023-08-01 14:18:44 +08:00
msg: b ? 'error' : "ok",
2023-08-01 13:02:12 +08:00
data: json
}
})
/**
* 设置配置文件接口
*/
2023-08-03 21:09:57 +08:00
router.post('/setConfig', async (req, res) => {
if (req.request.body === undefined) {
req.body = {
code: -1,
msg: "提交内容不能为空"
}
return
}
2023-08-01 14:18:44 +08:00
2023-08-03 21:09:57 +08:00
let b = config.setConfig(req.request.body);
req.body = {
code: b ? 0 : -2,
msg: b ? 'ok' : "error",
}
2023-08-01 13:02:12 +08:00
})
2023-08-03 21:09:57 +08:00
module.exports = router