| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- const API = require('../../../../lib/API')
- const AccessControl = require('../../../../lib/AccessControl')
- const { BaseStdResponse } = require('../../../../BaseStdResponse')
- const { patchGlobal } = require('../../../../lib/Lepao/lepaoProxyPoolService')
- class SetGlobal extends API {
- constructor() {
- super()
- this.setPath('/Admin/Lepao/Proxy/SetGlobal')
- this.setMethod('post')
- }
- async onRequest(req, res) {
- const { uuid, session, random_proxy_enabled, import_url, probe_target_url, check_timeout_ms, check_concurrency } =
- req.body
- if ([uuid, session].some((v) => v === '' || v === null || v === undefined)) {
- return res.json({ ...BaseStdResponse.MISSING_PARAMETER })
- }
- if (!await AccessControl.checkSession(uuid, session)) {
- return res.status(401).json({ ...BaseStdResponse.ACCESS_DENIED })
- }
- const permission = await AccessControl.getPermission(uuid)
- if (!permission.includes('admin') && !permission.includes('service')) {
- return res.json({ ...BaseStdResponse.PERMISSION_DENIED })
- }
- const patch = {}
- if (random_proxy_enabled !== undefined) patch.random_proxy_enabled = random_proxy_enabled
- if (import_url !== undefined) patch.import_url = import_url
- if (probe_target_url !== undefined) patch.probe_target_url = probe_target_url
- if (check_timeout_ms !== undefined) patch.check_timeout_ms = check_timeout_ms
- if (check_concurrency !== undefined) patch.check_concurrency = check_concurrency
- try {
- const r = await patchGlobal(patch)
- return res.json({ ...BaseStdResponse.OK, data: r })
- } catch (e) {
- return res.json({ ...BaseStdResponse.ERR, msg: e.message || '保存失败' })
- }
- }
- }
- module.exports.SetGlobal = SetGlobal
|