|
@@ -868,33 +868,35 @@ module.exports = app => {
|
|
* @param {*} ctx 上下文
|
|
* @param {*} ctx 上下文
|
|
*/
|
|
*/
|
|
async upload(ctx) {
|
|
async upload(ctx) {
|
|
- let stream;
|
|
|
|
try {
|
|
try {
|
|
await this._checkMaterialFileCanModify(ctx);
|
|
await this._checkMaterialFileCanModify(ctx);
|
|
- const parts = this.ctx.multipart({
|
|
|
|
- autoFields: true,
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
const files = [];
|
|
const files = [];
|
|
- const create_time = Date.parse(new Date()) / 1000;
|
|
|
|
let idx = 0;
|
|
let idx = 0;
|
|
|
|
+ const create_time = Date.parse(new Date()) / 1000;
|
|
const extra_upload = ctx.material.status === auditConst.status.checked;
|
|
const extra_upload = ctx.material.status === auditConst.status.checked;
|
|
- while ((stream = await parts()) !== undefined) {
|
|
|
|
- if (!stream.filename) {
|
|
|
|
- // 如果没有传入直接返回
|
|
|
|
- return;
|
|
|
|
|
|
+ for (const file of ctx.request.files) {
|
|
|
|
+ // 如果没有传入直接返回
|
|
|
|
+ if (!file.filename) return;
|
|
|
|
+ try {
|
|
|
|
+ const fileInfo = path.parse(file.filename);
|
|
|
|
+ const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx.toString() + fileInfo.ext}`;
|
|
|
|
+ await this.ctx.helper.recursiveMkdirSync(path.dirname(path.join(this.app.baseDir, 'app', filepath)));
|
|
|
|
+ await fs.copyFileSync(file.filepath, path.resolve(this.app.baseDir, 'app', filepath));
|
|
|
|
+ files.push({
|
|
|
|
+ filepath, name: file.filename, ext: fileInfo.ext
|
|
|
|
+ });
|
|
|
|
+ } finally {
|
|
|
|
+ await fs.unlinkSync(file.filepath);
|
|
}
|
|
}
|
|
- const fileInfo = path.parse(stream.filename);
|
|
|
|
- // const filepath = path.join('public/upload', this.ctx.tender.id.toString(), 'tc', 'fujian_' + create_time + fileInfo.ext);
|
|
|
|
- const filepath = `public/upload/${this.ctx.tender.id.toString()}/tc/fujian_${create_time + idx.toString() + fileInfo.ext}`;
|
|
|
|
- await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
|
|
|
|
- files.push({ filepath, name: stream.filename, ext: fileInfo.ext });
|
|
|
|
++idx;
|
|
++idx;
|
|
}
|
|
}
|
|
|
|
+
|
|
const upload_time = this.ctx.helper.dateTran(new Date());
|
|
const upload_time = this.ctx.helper.dateTran(new Date());
|
|
const payload = files.map(file => {
|
|
const payload = files.map(file => {
|
|
let idx;
|
|
let idx;
|
|
- if (Array.isArray(parts.field.name)) {
|
|
|
|
- idx = parts.field.name.findIndex(name => name === file.name);
|
|
|
|
|
|
+ if (Array.isArray(ctx.request.body.name)) {
|
|
|
|
+ idx = ctx.request.body.name.findIndex(name => name === file.name);
|
|
} else {
|
|
} else {
|
|
idx = 'isString';
|
|
idx = 'isString';
|
|
}
|
|
}
|
|
@@ -905,7 +907,7 @@ module.exports = app => {
|
|
s_order: ctx.params.order,
|
|
s_order: ctx.params.order,
|
|
upload_time,
|
|
upload_time,
|
|
filepath: file.filepath,
|
|
filepath: file.filepath,
|
|
- file_size: ctx.helper.bytesToSize(idx === 'isString' ? parts.field.size : parts.field.size[idx]),
|
|
|
|
|
|
+ file_size: ctx.helper.bytesToSize(idx === 'isString' ? ctx.request.body.size : ctx.request.body.size[idx]),
|
|
file_name: file.name,
|
|
file_name: file.name,
|
|
fileext: file.ext,
|
|
fileext: file.ext,
|
|
extra_upload,
|
|
extra_upload,
|
|
@@ -918,7 +920,6 @@ module.exports = app => {
|
|
const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
|
|
const data = await ctx.service.materialFile.getAllMaterialFiles(ctx.tender.id);
|
|
ctx.body = { err: 0, msg: '', data };
|
|
ctx.body = { err: 0, msg: '', data };
|
|
} catch (err) {
|
|
} catch (err) {
|
|
- stream && (await sendToWormhole(stream));
|
|
|
|
this.log(err);
|
|
this.log(err);
|
|
ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
}
|
|
}
|