添加获取大区热更新地址的接口

This commit is contained in:
liangtongchuan
2022-05-05 20:01:55 +08:00
parent c4793c7e8a
commit c263c44a90
6 changed files with 33 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ export const STATUS = {
ONLINE_USER_MAX: { code: 13, simStr: '服务器繁忙,请稍后再试' },
FUNCTION_CLOSE: { code: 14, simStr: '抱歉,该功能暂时关闭' },
GLOBAL_ERR: { code: 1003, simStr: '服务器内部错误' },
UPDATE_INFO_ERR: {code: 1004, simStr: '热更新配置错误'},
// http请求
REQUEST_TIME_OUT: { code: 2000, simStr: '请求超时' },
REQUEST_FAIL: { code: 2001, simStr: '请求错误' },

View File

@@ -40,7 +40,13 @@ export default class Region extends BaseModel {
latestServer: number; // 最新服
@prop({ required: true })
versionCode: number; // 版本号
versionCode: number; // 支持的最小版本号
@prop({ required: true })
curVersion: number; // 当前版本号
@prop({ required: true }) // 热更新资源根目录
updateResUrl: string;
@prop({ required: true })
latestServerUniqId: number; // 最新服唯一id

View File

@@ -75,6 +75,7 @@ export class UpdateRegionParams {
prefix: string = ''; // 区名前缀
remark: string = '';
versionCode: number = 1;
curVersion: number = 0;
maxPlayerCnt: number = 0;
timers: SERVER_TIMER[] = [];
@@ -93,7 +94,7 @@ export class UpdateRegionParams {
}
checkParams() {
if(!this.id || !this.name || !this.prefix || !this.maxPlayerCnt || !isArray(this.timers) || this.timers.length <= 0 || !isArray(this.activityGroupId) || this.activityGroupId.length <= 0 || !isNumber(this.versionCode)) {
if(!this.id || !this.name || !this.prefix || !this.maxPlayerCnt || !isArray(this.timers) || this.timers.length <= 0 || !isArray(this.activityGroupId) || this.activityGroupId.length <= 0 || !isNumber(this.versionCode) || !isNumber(this.curVersion)) {
return false
}
return true;
@@ -107,6 +108,7 @@ export class UpdateRegionParams {
prefix: this.prefix,
remark: this.remark,
versionCode: this.versionCode,
curVersion: this.curVersion,
stategy
}
} else {
@@ -116,6 +118,7 @@ export class UpdateRegionParams {
prefix: this.prefix||oldRegion.prefix,
remark: this.remark||oldRegion.remark,
versionCode: this.versionCode||oldRegion.versionCode,
curVersion: this.curVersion||oldRegion.curVersion,
stategy: { ...(oldRegion.stategy||{}), ...stategy }
}
}

View File

@@ -1,4 +1,5 @@
import { Controller } from 'egg';
import { RegionModel } from '@db/Region';
export default class UpdateController extends Controller {
public async getversion() {
@@ -7,4 +8,11 @@ export default class UpdateController extends Controller {
ctx.body = await ctx.service.update.getVersion(version);
}
public async getUpdateUrl() {
const { ctx } = this;
const env = this.app.config.realEnv;
const curRegion = await RegionModel.findRegionByEnv(env);
const { curVersion, updateResUrl } = curRegion;
ctx.body = await ctx.service.update.getUpdateUrl(env, curVersion, updateResUrl);
}
}

View File

@@ -23,6 +23,7 @@ export default (app: Application) => {
router.post('/game/getnotice', tokenParser, controller.game.getnotice);
router.post('/gate/queryenter', tokenParser, controller.game.queryEnter);
router.post('/update/getversion', controller.update.getversion);
router.post('/update/getupdateurl', controller.update.getUpdateUrl);
router.post('/web/reloadresource', app.middleware.gmTokenParser(), controller.game.reloadResource);

View File

@@ -22,5 +22,17 @@ export default class Update extends Service {
remoteVersionUrl: 'http://zyz-hot-update.trgame.cn/version.manifest'
});
}
public async getUpdateUrl(env: string, curVersion: number, updateResUrl: string) {
const ctx = this.ctx;
if (!env || !curVersion || !updateResUrl) return ctx.service.utils.resResult(STATUS.UPDATE_INFO_ERR);
const baseUrl = `${updateResUrl}/${env}/${curVersion}`;
return ctx.service.utils.resResult(STATUS.SUCCESS, {
packageUrl: baseUrl,
remoteManifestUrl: `${baseUrl}/project.manifest`,
remoteVersionUrl: `${baseUrl}/version.manifest`
});
}
}