后台:白名单

This commit is contained in:
luying
2021-12-08 20:45:06 +08:00
parent 46108f90f2
commit 24a9295ff3
7 changed files with 130 additions and 37 deletions

View File

@@ -31,6 +31,30 @@ export default class GameController extends Controller {
return
}
public async getWhiteList() {
const { ctx } = this;
const { id } = ctx.request.body;
ctx.body = await ctx.service.game.getWhiteList(id);
return
}
public async updateWhiteList() {
const { ctx } = this;
const { id, code, type, content } = ctx.request.body;
ctx.body = await ctx.service.game.updateWhiteList(id, code, type, content);
return
}
public async deleteWhiteList() {
const { ctx } = this;
const { id, code } = ctx.request.body;
ctx.body = await ctx.service.game.deleteWhiteList(id, code);
return
}
public async getServers() {
const { ctx } = this;

View File

@@ -55,6 +55,9 @@ export default (app: Application) => {
router.post('/api/game/getregions', controller.game.getRegions);
router.post('/api/game/getservers', controller.game.getServers);
router.post('/api/game/getregionstategy', controller.game.getRegionStategy);
router.post('/api/game/getwhitelist', controller.game.getWhiteList);
router.post('/api/game/updatewhitelist', controller.game.updateWhiteList);
router.post('/api/game/deletewhitelist', controller.game.deleteWhiteList);
router.post('/api/game/stopserverregister', controller.game.stopServerRegister);
router.post('/api/game/swicthserverstatus', controller.game.switchServerStatus);

View File

@@ -13,6 +13,8 @@ import { AccuseRecModel } from '@db/AccuseRec';
import { RegionModel } from '@db/Region';
import { ActivityGroupModel } from '@db/ActivityGroup';
import { nowSeconds } from '@pubUtils/timeUtil';
import { WhiteListModel } from '@db/RegionWhiteList';
import { RoleModel } from '@db/Role';
/**
* Test Service
@@ -90,6 +92,42 @@ export default class Game extends Service {
});
}
public async getWhiteList(id: number) {
const { ctx } = this;
let region = await RegionModel.findRegionById(id);
if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
let whitelist = await WhiteListModel.findByRegionId(id);
return ctx.service.utils.resResult(STATUS.SUCCESS, {
whitelist
});
}
public async updateWhiteList(id: number, code: string, type: number, content: string) {
const { ctx } = this;
let region = await RegionModel.findRegionById(id);
if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
if(type == 1) {
let whitelist = await WhiteListModel.updateWhiteList(code, { type, regionId: region.id, env: region.env, ip: content });
return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist });
} else if(type == 2) {
let role = await RoleModel.findByRoleId(content, 'roleId userInfo serverId roleName');
let whitelist = await WhiteListModel.updateWhiteList(code, { type, regionId: region.id, env: region.env, uid: role.userInfo.uid, serverId: role.serverId, roleId: role.roleId, roleName: role.roleName });
return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist });
} else {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}
}
public async deleteWhiteList(id: number, code: string) {
const { ctx } = this;
let region = await RegionModel.findRegionById(id);
if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
let whitelist = await WhiteListModel.deleteWhiteList(code);
return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist });
}
// public async getMaintenanceList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { isOpen?: boolean } = {}) {
// const { ctx } = this;