From 348ede5c63d8a77501facfa4701ca2de892fb301 Mon Sep 17 00:00:00 2001 From: luying Date: Tue, 11 Apr 2023 17:26:46 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(=E5=90=8E=E5=8F=B0):=20?= =?UTF-8?q?=E7=B2=BE=E5=BD=A9=E4=BA=8B=E4=BB=B6=E5=90=8E=E5=8F=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gm-server/app/controller/upload.ts | 20 ++++++++++++++------ gm-server/config/config.default.ts | 4 ++-- shared/pubUtils/battleUtils.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gm-server/app/controller/upload.ts b/gm-server/app/controller/upload.ts index 7c1b1c7e6..c31a32768 100644 --- a/gm-server/app/controller/upload.ts +++ b/gm-server/app/controller/upload.ts @@ -15,7 +15,7 @@ const publishPath = '/root/hot_update_backup'; import {exec} from 'child_process' import { reloadResources } from '@pubUtils/data'; import { decodeArrayStr } from '@pubUtils/util'; -import { getLocalQrCodeUrl, getRemoteQrCodeUrl } from '@pubUtils/battleUtils'; +import { getLocalPopNoticeUrl, getLocalQrCodeUrl, getRemotePopNoticeUrl, getRemoteQrCodeUrl } from '@pubUtils/battleUtils'; const sendToWormhole = require('stream-wormhole'); export default class UploadController extends Controller { @@ -284,7 +284,7 @@ public async uploadQrCode() { try { const { ctx } = this; const parts = ctx.multipart(); - let part, env = ctx.request.headers.env, fileName = ''; + let part, env = ctx.request.headers.env, type = ctx.request.headers.type, fileName = '', writePath = '', ext = '', remoteUrl = ''; while ((part = await parts()) != null) { if (part.length) { console.log('kv: ', `${part[0]}: ${part[1]}`); @@ -292,9 +292,17 @@ public async uploadQrCode() { if (!part.filename) continue; let filenames = part.filename.split('.'); - let ext = filenames[filenames.length - 1]; - let writePath = getLocalQrCodeUrl(this.app.config.realEnv, env); - fileName = `QR${moment().valueOf()}.${ext}`; + ext = filenames[filenames.length - 1]; + if(type == 'popNotice') { + writePath = getLocalPopNoticeUrl(this.app.config.realEnv); + fileName = `${moment().valueOf()}.${ext}`; + remoteUrl = getRemotePopNoticeUrl(this.app.config.realEnv, fileName); + } else { + writePath = getLocalQrCodeUrl(this.app.config.realEnv, env); + fileName = `QR${moment().valueOf()}.${ext}`; + remoteUrl = getRemoteQrCodeUrl(env, fileName); + } + let fullPath = `${writePath}/${fileName}`; try { fs.accessSync(writePath); @@ -313,7 +321,7 @@ public async uploadQrCode() { } await sendToWormhole(part); } - ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: true, url: getRemoteQrCodeUrl(env, fileName) }); + ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: true, url: remoteUrl, ext }); return; } catch(e) { ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: false, err: e.stack }); diff --git a/gm-server/config/config.default.ts b/gm-server/config/config.default.ts index 3118da750..ed1d4fd74 100644 --- a/gm-server/config/config.default.ts +++ b/gm-server/config/config.default.ts @@ -47,9 +47,9 @@ export default (appInfo: EggAppInfo) => { fileSize: '100mb', mode: 'stream', whitelist: [ - '.json', '.ts', '.zip', '.jpg', '.png', '.jpeg' + '.json', '.ts', '.zip', '.jpg', '.png', '.jpeg', '.mp4', '.gif' ], - fileExtensions: ['.json', '.ts', '.zip', '.tar.gz'], // 扩展几种上传的文件格式 + fileExtensions: ['.json', '.ts', '.zip', '.jpg', '.png', '.jpeg', '.mp4', '.gif'], // 扩展几种上传的文件格式 autoFields: true }; diff --git a/shared/pubUtils/battleUtils.ts b/shared/pubUtils/battleUtils.ts index b80684b70..02b23d200 100644 --- a/shared/pubUtils/battleUtils.ts +++ b/shared/pubUtils/battleUtils.ts @@ -17,6 +17,7 @@ function getPrefixByEnv(env: string) { case 'monitor': case 'alpha': case 'stable': + case 'distribute': return CDN_URL_PREFIX_ZYZ; case 'sq1': case 'sq4': @@ -62,3 +63,16 @@ export function getRemoteQrCodeUrl(env: string, fileName: string) { const rplUrl = `${getPrefixByEnv(env)}/img/${md5(env).substring(0, 4)}/qrcode/` + fileName; return rplUrl; } + +export function getLocalPopNoticeUrl(curEnv: string) { + if(curEnv == 'development') { + return './img' + } else { + return `/zyz_logs/img/popNotice`; + } +} + +export function getRemotePopNoticeUrl(curEnv: string, fileName: string) { + const rplUrl = `${getPrefixByEnv(curEnv)}/img/popNotice/` + fileName; + return rplUrl; +} \ No newline at end of file