✨ feat(后台): 精彩事件后台上传图片
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user