后台:上传资源
This commit is contained in:
@@ -14,9 +14,9 @@ const hotUpdateAddr = `/root/${folderName}`;
|
||||
const publishPath = '/root/hot_update_backup';
|
||||
import {exec} from 'child_process'
|
||||
import { reloadResources } from '@pubUtils/data';
|
||||
import { decodeArrayStr } from '@pubUtils/util';
|
||||
const sendToWormhole = require('stream-wormhole');
|
||||
|
||||
|
||||
export default class UploadController extends Controller {
|
||||
|
||||
private deleteFolder (path) {
|
||||
@@ -148,7 +148,7 @@ export default class UploadController extends Controller {
|
||||
// 解压上传文件的stream
|
||||
var unzipExtractor = unzip.Extract({ path: dirPath });
|
||||
unzipExtractor.on('close', function() {
|
||||
resolve();
|
||||
resolve(null);
|
||||
});
|
||||
|
||||
unzipExtractor.on('close', function(e) {
|
||||
@@ -170,26 +170,30 @@ export default class UploadController extends Controller {
|
||||
public async uploadJson() {
|
||||
const { ctx } = this;
|
||||
|
||||
|
||||
const parts = ctx.multipart({ });
|
||||
const files = [];
|
||||
|
||||
try {
|
||||
let stream;
|
||||
let writeStream;
|
||||
|
||||
while ((stream = await parts()) != null) {
|
||||
console.log('******', stream);
|
||||
const filename = stream.filename;
|
||||
let filenameWithoutEx = filename?filename.split('.')[0]:'';
|
||||
if (stream.mimeType == 'application/json') {
|
||||
if (filenameWithoutEx.match(/^\d{1,}$/)) {
|
||||
let target1 = path.join(this.config.baseDir, this.warjsonFolder, filename);
|
||||
let target2 = path.join(this.config.baseDir, this.distWarjsonFolder, filename);
|
||||
const writeStream = fs.createWriteStream(target1);
|
||||
writeStream = fs.createWriteStream(target1);
|
||||
await pump(stream, writeStream);
|
||||
fs.copyFileSync(target1, target2);
|
||||
files.push(filename);
|
||||
} else {
|
||||
let target1 = path.join(this.config.baseDir, this.jsonFolder, filename);
|
||||
let target2 = path.join(this.config.baseDir, this.distJsonFolder, filename);
|
||||
const writeStream = fs.createWriteStream(target1);
|
||||
writeStream = fs.createWriteStream(target1);
|
||||
await pump(stream, writeStream);
|
||||
fs.copyFileSync(target1, target2);
|
||||
files.push(filename);
|
||||
@@ -197,13 +201,23 @@ export default class UploadController extends Controller {
|
||||
} else if (stream.mimeType == 'application/octet-stream') {
|
||||
let target1 = path.join(this.config.baseDir, this.tsFolder, 'dicParam.js');
|
||||
let target2 = path.join(this.config.baseDir, this.distTsFolder, filename);
|
||||
const writeStream = fs.createWriteStream(target1);
|
||||
writeStream = fs.createWriteStream(target1);
|
||||
await pump(stream, writeStream);
|
||||
fs.copyFileSync(target1, target2);
|
||||
files.push(filename);
|
||||
}
|
||||
|
||||
let envs = decodeArrayStr(ctx.request.headers.env||'', ',');
|
||||
|
||||
if(envs.length > 0) { // 转发
|
||||
for(let env of envs) {
|
||||
if(env == ctx.app.config.realEnv) continue;
|
||||
await ctx.service.utils.transmit(env, ctx.request.url, writeStream);
|
||||
}
|
||||
}
|
||||
sendToWormhole(stream);
|
||||
}
|
||||
|
||||
}catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user