| 12345678910111213141516171819202122232425262728293031323334353637 |
- const API = require("../../../../lib/API");
- const AccessControl = require("../../../../lib/AccessControl");
- const { BaseStdResponse } = require("../../../../BaseStdResponse");
- const VersionService = require("../../../../lib/DownloadVersionService");
- class AdminDownloadVersionUpsert extends API {
- constructor() {
- super();
- this.setPath('/Admin/DownloadVersion');
- this.setMethod('POST');
- }
- async onRequest(req, res) {
- const { uuid, session, client_type, version_name, download_url } = req.body;
- if ([uuid, session, client_type, version_name, download_url].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 });
- try {
- const { id, result } = await VersionService.saveVersion(req.body);
- if (!result || result.affectedRows === 0)
- return res.json({ ...BaseStdResponse.ERR, msg: '保存下载版本失败' });
- return res.json({ ...BaseStdResponse.OK, id });
- } catch (err) {
- this.logger.error(`保存下载版本失败:${err.stack || err}`);
- return res.json({ ...BaseStdResponse.ERR, msg: '保存下载版本失败' });
- }
- }
- }
- module.exports.AdminDownloadVersionUpsert = AdminDownloadVersionUpsert;
|