✨ feat(录像): 修改录像上传逻辑
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
var fs = require('fs');
|
||||
function main (){
|
||||
var args = process.argv.splice(2)
|
||||
if (args.length !== 1) {
|
||||
if (args.length !== 2) {
|
||||
return console.log('参数请填写环境变量');
|
||||
}
|
||||
let env = args[0];
|
||||
let sshHost = args[1];
|
||||
|
||||
let configObject = {
|
||||
env: env
|
||||
};
|
||||
let result = JSON.stringify(configObject);
|
||||
let sshHostResult = `export const sshHost = "${sshHost}";`
|
||||
|
||||
fs.writeFileSync(__dirname + '/game-server/config.json', result, 'utf8');
|
||||
fs.writeFileSync(__dirname + '/gm-server/config/env', env, 'utf8');
|
||||
fs.writeFileSync(__dirname + '/web-server/config/env', env, 'utf8');
|
||||
fs.writeFileSync(__dirname + '/web-server/config/sshHost.ts', sshHostResult, 'utf8');
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
@@ -360,8 +360,8 @@ export class LadderHandler {
|
||||
let list = await LadderMatchRecModel.findRecentRec(roleId, <number>getTimeFunM().getBeforeDay(2));
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: list.map(rec => {
|
||||
const { roleId1, battleCode, hasRpl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(roleId1, WAR_TYPE.LADDER, battleCode) : '';
|
||||
const { roleId1, battleCode, hasRpl, remoteUrl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(remoteUrl, roleId1, WAR_TYPE.LADDER, battleCode) : '';
|
||||
return { ...rec, rplFileUrl };
|
||||
}),
|
||||
rplPrefixUrl: getRemoteRplPrefix(pinus.app.get('env'))
|
||||
|
||||
@@ -618,8 +618,8 @@ export class PvpHandler {
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: pvpRecords.map(rec => {
|
||||
const { roleId1, battleCode, hasRpl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(roleId1, WAR_TYPE.PVP, battleCode) : '';
|
||||
const { roleId1, battleCode, hasRpl, remoteUrl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(remoteUrl, roleId1, WAR_TYPE.PVP, battleCode) : '';
|
||||
return { ...rec, rplFileUrl };
|
||||
}),
|
||||
rplPrefixUrl: getRemoteRplPrefix(pinus.app.get('env'))
|
||||
|
||||
@@ -395,8 +395,8 @@ export class GVGProduceHandler {
|
||||
let list = await GVGVestigeRecModel.findRec(roleId, vestigeId);
|
||||
let result: (GVGVestigeRecUpdate & {rplFileUrl: string})[] = [];
|
||||
for(let rec of list) {
|
||||
const { attackRoleId, battleCode, hasRpl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(attackRoleId, WAR_TYPE.GVG_VESTIGE, battleCode) : '';
|
||||
const { attackRoleId, battleCode, hasRpl, remoteUrl } = rec;
|
||||
const rplFileUrl = battleCode && hasRpl ? getRemoteRplFilePath(remoteUrl, attackRoleId, WAR_TYPE.GVG_VESTIGE, battleCode) : '';
|
||||
const obj = getVestigeRecStatus(rec);
|
||||
if(obj.status == VESTIGE_STATUS.COMPLETE) result.push({ ...rec, endTime: obj.time, rplFileUrl });
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ fi
|
||||
echo "|*********************|\n"
|
||||
|
||||
echo "and config.json is: \n"
|
||||
node ./config.js ${env}
|
||||
node ./config.js ${env} ${1}
|
||||
cat './game-server/config.json'
|
||||
echo "\n"
|
||||
echo "|*********************|\n"
|
||||
@@ -157,3 +157,4 @@ esac
|
||||
git checkout ./game-server/config.json
|
||||
git checkout ./gm-server/config/env
|
||||
git checkout ./web-server/config/env
|
||||
git checkout ./web-server/config/sshHost
|
||||
|
||||
@@ -97,6 +97,9 @@ export default class GVGBattleRec extends BaseModel {
|
||||
@prop({ required: true, default: false })
|
||||
hasRpl: boolean; // 是否存在对应录像
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
remoteUrl: string; // 录像地址
|
||||
|
||||
public static async createRec(configId: number, groupKey: string, warId: number, attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
|
||||
const battleCode = genCode(8);
|
||||
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { configId, groupKey, warId, attackTeam, defenseTeam, isSuccess: false } }, { new: true, upsert: true }).lean();
|
||||
@@ -113,8 +116,8 @@ export default class GVGBattleRec extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean) {
|
||||
let result = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { hasRpl }, { new: true }).lean();
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean, remoteUrl: string) {
|
||||
let result = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { hasRpl, remoteUrl }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,9 @@ export default class GVGVestigeRec extends BaseModel {
|
||||
@prop({ required: true, default: false })
|
||||
hasRpl: boolean; // 是否存在对应录像
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
remoteUrl: string; // 录像文件
|
||||
|
||||
public static async createRec(configId: number, vestigeId: number, groupKey: string, warId: number, attackInfo: OppPlayerInfo, defenseInfo: OppPlayerInfo, leagueGoods: LeagueGood[]) {
|
||||
const battleCode = genCode(10);
|
||||
const result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, {
|
||||
@@ -110,8 +113,8 @@ export default class GVGVestigeRec extends BaseModel {
|
||||
}
|
||||
|
||||
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean) {
|
||||
let result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, { hasRpl }, { new: true }).lean();
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean, remoteUrl: string) {
|
||||
let result: GVGVestigeRecType = await GVGVestigeRecModel.findOneAndUpdate({ battleCode }, { hasRpl, remoteUrl }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ export default class LadderMatchRec extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
hasRpl: boolean; // 是否存在对应录像
|
||||
@prop({ required: true, default: false })
|
||||
remoteUrl: string; // 录像地址
|
||||
|
||||
public static async findByRoleId(roleId: string, getters = false) {
|
||||
const result: LadderMatchRecType = await LadderMatchRecModel.findOne({ roleId1: roleId }).lean({ getters});
|
||||
@@ -143,8 +145,8 @@ export default class LadderMatchRec extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean) {
|
||||
let result = await LadderMatchRecModel.findOneAndUpdate({ battleCode }, { hasRpl }, { new: true }).lean();
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean, remoteUrl: string) {
|
||||
let result = await LadderMatchRecModel.findOneAndUpdate({ battleCode }, { hasRpl, remoteUrl }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,8 @@ export default class PvpRecord extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
hasRpl: boolean; // 是否存在对应录像
|
||||
@prop({ required: true, default: false })
|
||||
remoteUrl: string; // 远程地址
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
createTime: number;
|
||||
@@ -167,8 +169,8 @@ export default class PvpRecord extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean) {
|
||||
let result = await PvpRecordModel.findOneAndUpdate({ battleCode }, { hasRpl }, { new: true }).lean();
|
||||
public static async updateRplStatus(battleCode: string, hasRpl: boolean, remoteUrl: string) {
|
||||
let result = await PvpRecordModel.findOneAndUpdate({ battleCode }, { hasRpl, remoteUrl }, { new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { md5 } from './sdkUtil';
|
||||
const BATTLE_CLASS_MOD = 100; // 存档分类模数
|
||||
const CDN_URL_PREFIX_SQ = 'https://download-sgzzyz.yev242.com'; // sq cdn 服务器地址前缀
|
||||
const CDN_URL_PREFIX_ZYZ = 'http://zyz-download.trgame.cn'; // 公司下载服务器地址前缀
|
||||
const CDN_URL_PREFIX_YJZ = 'https://yjz-cdn.yev242.com'; // 公司下载服务器地址前缀
|
||||
|
||||
// 将字符串 crc32 处理后取模,以将随机字符串分组
|
||||
function modStr(str: string, mod: number) {
|
||||
@@ -23,8 +24,10 @@ function getPrefixByEnv(env: string) {
|
||||
case 'sq4':
|
||||
case 'sq7':
|
||||
case 'sq9':
|
||||
default:
|
||||
return CDN_URL_PREFIX_SQ;
|
||||
case 'zy1':
|
||||
return CDN_URL_PREFIX_YJZ;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +37,9 @@ export function getLocalRplUrl(roleId: string, warType: number, battleCode: stri
|
||||
return writePath;
|
||||
}
|
||||
|
||||
export function getRemoteRplUrl(env: string, roleId: string, warType: number, battleCode: string) {
|
||||
export function getRemoteRplUrl(env: string, sshHost: string, roleId: string, warType: number, battleCode: string) {
|
||||
const battleClass = modStr(battleCode, BATTLE_CLASS_MOD); // 将存档文件按一定规则分批保存
|
||||
const rplUrl = `${getPrefixByEnv(env)}/rpls/${md5(env).substring(0, 4)}/${roleId}/${warType}/${battleClass}`;
|
||||
const rplUrl = `${getPrefixByEnv(env)}/rpls/${md5(sshHost).substring(0, 4)}/${roleId}/${warType}/${battleClass}`;
|
||||
return rplUrl;
|
||||
}
|
||||
|
||||
@@ -45,7 +48,8 @@ export function getRemoteRplPrefix(env: string) {
|
||||
return rplUrl;
|
||||
}
|
||||
|
||||
export function getRemoteRplFilePath(roleId: string, warType: number, battleCode: string) {
|
||||
export function getRemoteRplFilePath(remoteUrl: string, roleId: string, warType: number, battleCode: string) {
|
||||
if(remoteUrl) return remoteUrl;
|
||||
const battleClass = modStr(battleCode, BATTLE_CLASS_MOD); // 将存档文件按一定规则分批保存
|
||||
const rplUrl = `/${roleId}/${warType}/${battleClass}/${battleCode}.bin`;
|
||||
return rplUrl;
|
||||
|
||||
@@ -267,18 +267,18 @@ export default class GameController extends Controller {
|
||||
const writeStream = fs.createWriteStream(fullPath);
|
||||
await pump(part, writeStream);
|
||||
|
||||
remoteUrl = `${getRemoteRplUrl(ctx.app.config.realEnv, ctx.app.config.sshHost,roleId, warType, battleCode)}/${battleCode}.bin`;
|
||||
let updateDBRes;
|
||||
if (warType === WAR_TYPE.PVP) {
|
||||
updateDBRes = await PvpRecordModel.updateRplStatus(battleCode, true);
|
||||
updateDBRes = await PvpRecordModel.updateRplStatus(battleCode, true, remoteUrl);
|
||||
} else if (warType === WAR_TYPE.LADDER) {
|
||||
updateDBRes = await LadderMatchRecModel.updateRplStatus(battleCode, true);
|
||||
updateDBRes = await LadderMatchRecModel.updateRplStatus(battleCode, true, remoteUrl);
|
||||
} else if (warType == WAR_TYPE.GVG_VESTIGE) {
|
||||
updateDBRes = await GVGVestigeRecModel.updateRplStatus(battleCode, true);
|
||||
updateDBRes = await GVGVestigeRecModel.updateRplStatus(battleCode, true, remoteUrl);
|
||||
} else if (warType == WAR_TYPE.GVG_BATTLE) {
|
||||
updateDBRes = await GVGBattleRecModel.updateRplStatus(battleCode, true);
|
||||
updateDBRes = await GVGBattleRecModel.updateRplStatus(battleCode, true, remoteUrl);
|
||||
}
|
||||
if (!updateDBRes) return ctx.body = ctx.service.utils.resResult(STATUS.BATTLE_RPL_UPDATE_ERR);
|
||||
remoteUrl = `${getRemoteRplUrl(ctx.app.config.realEnv, roleId, warType, battleCode)}/${battleCode}.bin`;
|
||||
} else {
|
||||
await sendToWormhole(part);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||
import defaultConfig from './config.default';
|
||||
import { sshHost } from './sshHost';
|
||||
|
||||
export default (appInfo: EggAppInfo) => {
|
||||
const config = {} as PowerPartial<EggAppConfig>;
|
||||
@@ -18,6 +19,7 @@ export default (appInfo: EggAppInfo) => {
|
||||
};
|
||||
|
||||
config.decodeParm = true;
|
||||
config.sshHost = sshHost;
|
||||
|
||||
// the return config will combines to EggAppConfig
|
||||
return {
|
||||
|
||||
1
web-server/config/sshHost.ts
Normal file
1
web-server/config/sshHost.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const sshHost = "local";
|
||||
Reference in New Issue
Block a user