MaiXinRong 5 лет назад
Родитель
Сommit
edb417fd7c

+ 6 - 6
app/controller/change_controller.js

@@ -584,14 +584,14 @@ module.exports = app => {
                     }
                     const create_time = Date.parse(new Date()) / 1000;
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = '/upload/changes/' + moment().format('YYYYMMDD');
+                    const dirName = 'app/public/upload/changes/' + moment().format('YYYYMMDD');
                     const fileName = 'changes' + create_time + '_' + index + fileInfo.ext;
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
+                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
                     await sendToWormhole(stream);
                     // 保存数据到att表
                     const fileData = {
@@ -635,7 +635,7 @@ module.exports = app => {
                 try {
                     const fileInfo = await ctx.service.changeAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
-                        const fileName = path.join(this.app.config.filePath, fileInfo.filepath);
+                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -679,7 +679,7 @@ module.exports = app => {
                 const fileInfo = await ctx.service.changeAtt.getDataById(data.id);
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.config.filePath, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.changeAtt.deleteById(data.id);
                     responseData.data = '';

+ 17 - 17
app/controller/stage_controller.js

@@ -571,7 +571,7 @@ module.exports = app => {
                 const create_time = Date.parse(new Date()) / 1000;
                 const fileInfo = path.parse(stream.filename);
                 const fileName = path.join('public/upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + fileInfo.ext);
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, fileName));
+                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, 'app', fileName));
                 ctx.body = {err: 0, msg: '', data: fileName};
             } catch(err) {
                 this.log(err);
@@ -1196,17 +1196,17 @@ module.exports = app => {
                     if (!stream.filename) {
                         throw '请选择上传的文件!';
                     }
-                    const dirName = '/upload/stage/' + moment().format('YYYYMMDD');
+                    const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
+                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
                     }
                     const create_time = Date.parse(new Date()) / 1000;
                     const fileInfo = path.parse(stream.filename);
                     const fileName = 'stage' + create_time + '_' + index + fileInfo.ext;
 
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
 
                     if (stream) {
                         await sendToWormhole(stream);
@@ -1256,7 +1256,7 @@ module.exports = app => {
                 try {
                     const fileInfo = await ctx.service.stageAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
-                        const fileName = path.join(this.app.config.filePath, fileInfo.filepath);
+                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -1302,7 +1302,7 @@ module.exports = app => {
                 const fileInfo = await ctx.service.stageAtt.getDataById(data.id);
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.config.filePath, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.stageAtt.deleteById(data.id);
                     responseData.data = '';
@@ -1343,15 +1343,15 @@ module.exports = app => {
                 if (stream.filename !== undefined) {
                     const create_time = Date.parse(new Date()) / 1000;
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = '/upload/stage/' + moment().format('YYYYMMDD');
+                    const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
                     const fileName = 'stage' + create_time + fileInfo.ext;
 
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
+                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
                     // 保存数据到att表
                     fileData = {
                         filesize: stream.fields.size,
@@ -1403,15 +1403,15 @@ module.exports = app => {
                         throw '请选择上传的文件!';
                     }
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = '/upload/pay/' + moment().format('YYYYMMDD');
+                    const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
                     const fileName = 'pay' + create_time + '_' + index + fileInfo.ext;
 
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
+                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
                     await sendToWormhole(stream);
                     // 插入到stage_pay对应的附件列表中
                     const attData = {
@@ -1458,7 +1458,7 @@ module.exports = app => {
                     const payInfo = await ctx.service.stagePay.getDataById(id);
                     if (payInfo !== undefined && payInfo.attachment !== null) {
                         const fileInfo = JSON.parse(payInfo.attachment)[index];
-                        const fileName = path.join(this.app.config.filePath, fileInfo.filepath);
+                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -1505,7 +1505,7 @@ module.exports = app => {
                 if (payInfo !== undefined) {
                     const fileInfo = JSON.parse(payInfo.attachment)[data.index];
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.config.filePath, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
                     // 再删除数据库
                     const attachment = JSON.parse(payInfo.attachment);
                     attachment.splice(data.index, 1);

+ 1 - 1
app/service/change.js

@@ -874,7 +874,7 @@ module.exports = app => {
                 const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { cid } });
                 if (attList.length !== 0) {
                     for (const att of attList) {
-                        await fs.unlinkSync(path.join(this.app.config.filePath, att.filepath));
+                        await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
                     }
                     await this.transaction.delete(this.ctx.service.changeAtt.tableName, { cid });
                 }

+ 4 - 4
app/service/stage.js

@@ -326,8 +326,8 @@ module.exports = app => {
                         if (pt.attachment !== null && pt.attachment !== '') {
                             const payAttList = JSON.parse(pt.attachment);
                             for (const pat of payAttList) {
-                                if (fs.existsSync(path.join(this.app.config.filePath, pat.filepath))) {
-                                    await fs.unlinkSync(path.join(this.app.config.filePath, pat.filepath));
+                                if (fs.existsSync(path.join(this.app.baseDir, pat.filepath))) {
+                                    await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
                                 }
                             }
                         }
@@ -339,8 +339,8 @@ module.exports = app => {
                 const attList = await this.ctx.service.stageAtt.getAllDataByCondition({ where: { sid: id } });
                 if (attList.length !== 0) {
                     for (const att of attList) {
-                        if (fs.existsSync(path.join(this.app.config.filePath, att.filepath))) {
-                            await fs.unlinkSync(path.join(this.app.config.filePath, att.filepath));
+                        if (fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
+                            await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
                         }
                     }
                 }

+ 2 - 2
app/service/tender.js

@@ -282,8 +282,8 @@ module.exports = app => {
                 const attList = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { tid: id } });
                 if (attList.length !== 0) {
                     for (const att of attList) {
-                        if (fs.existsSync(path.join(this.app.config.filePath, att.filepath))) {
-                            await fs.unlinkSync(path.join(this.app.config.filePath, att.filepath));
+                        if (fs.existsSync(path.join(this.app.baseDir, att.filepath))) {
+                            await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
                         }
                     }
                 }