Browse Source

fix: 修复附件下载以往附件无法下载的bug

lanjianrong 4 years ago
parent
commit
b2bfdab4cb

+ 3 - 3
app/controller/change_controller.js

@@ -638,7 +638,7 @@ module.exports = app => {
                     // await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
                     const fileInfo = path.parse(stream.filename);
                     const create_time = Date.parse(new Date()) / 1000;
-                    const filepath = `public/upload/change/fujian_${create_time + index.toString() + fileInfo.ext}`;
+                    const filepath = `app/public/upload/change/fujian_${create_time + index.toString() + fileInfo.ext}`;
                     await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
                     await sendToWormhole(stream);
                     // 保存数据到att表
@@ -683,7 +683,7 @@ module.exports = app => {
                 try {
                     const fileInfo = await ctx.service.changeAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
-                        const fileName = path.join(this.app.baseDir, 'app', fileInfo.filepath);
+                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -727,7 +727,7 @@ module.exports = app => {
                 const fileInfo = await ctx.service.changeAtt.getDataById(data.id);
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.baseDir, './app', fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.changeAtt.deleteById(data.id);
                     responseData.data = '';

+ 4 - 4
app/controller/stage_controller.js

@@ -1304,8 +1304,8 @@ module.exports = app => {
                     // }
                     const fileInfo = path.parse(stream.filename);
                     const create_time = Date.parse(new Date()) / 1000;
-                    const filepath = `public/upload/${this.ctx.tender.id}/stage/fujian_${create_time + index.toString() + fileInfo.ext}`;
-                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, 'app', filepath));
+                    const filepath = `app/public/upload/${this.ctx.tender.id}/stage/fujian_${create_time + index.toString() + fileInfo.ext}`;
+                    await ctx.helper.saveStreamFile(stream, path.resolve(this.app.baseDir, filepath));
                     // console.log(await fs.existsSync(path.resolve(this.app.baseDir, 'app', filepath)));
                     // const fileInfo = path.parse(stream.filename);
                     // const fileName = 'stage' + create_time + '_' + index + fileInfo.ext;
@@ -1363,7 +1363,7 @@ module.exports = app => {
                 try {
                     const fileInfo = await ctx.service.stageAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
-                        const fileName = path.join(this.app.baseDir, 'app', fileInfo.filepath);
+                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -1407,7 +1407,7 @@ module.exports = app => {
                         if (!ctx.helper.canPreview(fileInfo.fileext)) {
                             filepath = `/tender/${ctx.tender.id}/measure/stage/${ctx.params.order}/download/file/${fileInfo.id}`;
                         } else {
-                            filepath = '/' + filepath;
+                            filepath = filepath.replace(/^app/, '');
                         }
                         fileInfo.filepath && (responseData.data = { filepath });
                     }

+ 1 - 1
app/service/change_att.js

@@ -65,7 +65,7 @@ module.exports = app => {
                 if (!ctx.helper.canPreview(item.fileext)) {
                     item.filepath = `/change/download/file/${item.id}`;
                 } else {
-                    item.filepath = '/' + item.filepath;
+                    item.filepath = item.filepath.replace(/^app/, '');
                 }
                 return item;
             });

+ 1 - 1
app/service/stage_att.js

@@ -63,7 +63,7 @@ module.exports = app => {
          */
         async getDataByTenderIdAndStageId(tid, sid) {
             const { ctx } = this;
-            const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.fileext, att.filesize, att.re_upload, att.remark, att.in_time,' +
+            const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.re_upload, att.remark, att.in_time,' +
                 ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`, leg.b_code as `b_code`' +
                 ' FROM ?? AS att,?? AS pa,?? AS leg' +
                 ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.tid = ? AND att.sid = ? ORDER BY att.id DESC';