Files
ZYZ/web-server/app/service/Update.ts

55 lines
1.9 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}/${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) {
try {
const ctx = this.ctx;
if(!curRegion || !curRegion.reviewVersion || !version) return false;
const versionsInReview = curRegion.reviewVersion.split(',');
if (!versionsInReview || versionsInReview.length <= 0) return false;
let reviewVersionFlag = versionsInReview.includes(version) ? true : false;
return `${ctx.clientIp}`.startsWith('17.') || reviewVersionFlag;
} catch(e) {
console.log('checkReview error: ', e);
return false;
}
}
}