ptSend/router/config.js
2023-08-03 21:41:18 +08:00

44 lines
831 B
JavaScript

/*
配置文件获取修改接口
*/
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 === '{}'
ctx.body = {
code: b ? -1 : 0,
msg: b ? 'error' : "ok",
data: json
}
})
/**
* 设置配置文件接口
*/
router.post('/setConfig', async (req, res) => {
if (req.request.body === undefined) {
req.body = {
code: -1,
msg: "提交内容不能为空"
}
return
}
let b = config.setConfig(req.request.body);
req.body = {
code: b ? 0 : -2,
msg: b ? 'ok' : "error",
}
})
module.exports = router