✨ feat(后台): 精彩事件后台上传图片
This commit is contained in:
@@ -15,7 +15,7 @@ const publishPath = '/root/hot_update_backup';
|
|||||||
import {exec} from 'child_process'
|
import {exec} from 'child_process'
|
||||||
import { reloadResources } from '@pubUtils/data';
|
import { reloadResources } from '@pubUtils/data';
|
||||||
import { decodeArrayStr } from '@pubUtils/util';
|
import { decodeArrayStr } from '@pubUtils/util';
|
||||||
import { getLocalQrCodeUrl, getRemoteQrCodeUrl } from '@pubUtils/battleUtils';
|
import { getLocalPopNoticeUrl, getLocalQrCodeUrl, getRemotePopNoticeUrl, getRemoteQrCodeUrl } from '@pubUtils/battleUtils';
|
||||||
const sendToWormhole = require('stream-wormhole');
|
const sendToWormhole = require('stream-wormhole');
|
||||||
|
|
||||||
export default class UploadController extends Controller {
|
export default class UploadController extends Controller {
|
||||||
@@ -284,7 +284,7 @@ public async uploadQrCode() {
|
|||||||
try {
|
try {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
const parts = ctx.multipart();
|
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) {
|
while ((part = await parts()) != null) {
|
||||||
if (part.length) {
|
if (part.length) {
|
||||||
console.log('kv: ', `${part[0]}: ${part[1]}`);
|
console.log('kv: ', `${part[0]}: ${part[1]}`);
|
||||||
@@ -292,9 +292,17 @@ public async uploadQrCode() {
|
|||||||
if (!part.filename) continue;
|
if (!part.filename) continue;
|
||||||
|
|
||||||
let filenames = part.filename.split('.');
|
let filenames = part.filename.split('.');
|
||||||
let ext = filenames[filenames.length - 1];
|
ext = filenames[filenames.length - 1];
|
||||||
let writePath = getLocalQrCodeUrl(this.app.config.realEnv, env);
|
if(type == 'popNotice') {
|
||||||
fileName = `QR${moment().valueOf()}.${ext}`;
|
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}`;
|
let fullPath = `${writePath}/${fileName}`;
|
||||||
try {
|
try {
|
||||||
fs.accessSync(writePath);
|
fs.accessSync(writePath);
|
||||||
@@ -313,7 +321,7 @@ public async uploadQrCode() {
|
|||||||
}
|
}
|
||||||
await sendToWormhole(part);
|
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;
|
return;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: false, err: e.stack });
|
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: false, err: e.stack });
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ export default (appInfo: EggAppInfo) => {
|
|||||||
fileSize: '100mb',
|
fileSize: '100mb',
|
||||||
mode: 'stream',
|
mode: 'stream',
|
||||||
whitelist: [
|
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
|
autoFields: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ function getPrefixByEnv(env: string) {
|
|||||||
case 'monitor':
|
case 'monitor':
|
||||||
case 'alpha':
|
case 'alpha':
|
||||||
case 'stable':
|
case 'stable':
|
||||||
|
case 'distribute':
|
||||||
return CDN_URL_PREFIX_ZYZ;
|
return CDN_URL_PREFIX_ZYZ;
|
||||||
case 'sq1':
|
case 'sq1':
|
||||||
case 'sq4':
|
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;
|
const rplUrl = `${getPrefixByEnv(env)}/img/${md5(env).substring(0, 4)}/qrcode/` + fileName;
|
||||||
return rplUrl;
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user