Files
ZYZ/web-server/app/service/Update.ts
2022-07-30 18:36:49 +08:00

48 lines
1.6 KiB
TypeScript

import { STATUS, } from '@consts';
import { RegionType } from '@db/Region';
import { Service } from 'egg';
// let fs = require("fs");
// const HOT_URL = 'http://zyz-hot-update.trgame.cn/version.manifest'
/**
* UpdateRes Service
*/
export default class Update extends Service {
/**
* 获取版本号
* @param version - 客户端版本号
*/
public async getVersion(version: string) {
const ctx = this.ctx;
console.log('client version: ', version);
return ctx.service.utils.resResult(STATUS.SUCCESS, {
packageUrl: 'http://zyz-hot-update.trgame.cn/',
remoteManifestUrl: 'http://zyz-hot-update.trgame.cn/project.manifest',
remoteVersionUrl: 'http://zyz-hot-update.trgame.cn/version.manifest'
});
}
public async getUpdateUrl(env: string, curVersion: string, 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`
});
}
public async checkReview(curRegion: RegionType, version: string) {
const ctx = this.ctx;
if(!curRegion || !curRegion.reviewVersion || !version) return false;
let reviewVersionFlag = ctx.service.utils.compareVersion(version, curRegion.reviewVersion);
return `${ctx.clientIp}`.startsWith('17.') || reviewVersionFlag > 0;
}
}