Explorar o código

文件存储目录统一调整

MaiXinRong %!s(int64=5) %!d(string=hai) anos
pai
achega
b354e0daed

+ 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 = 'app/public/upload/changes/' + moment().format('YYYYMMDD');
+                    const dirName = '/upload/changes/' + moment().format('YYYYMMDD');
                     const fileName = 'changes' + create_time + '_' + index + fileInfo.ext;
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
+                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, 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.baseDir, fileInfo.filepath);
+                        const fileName = path.join(this.app.config.filePath, 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.baseDir, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.config.filePath, fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.changeAtt.deleteById(data.id);
                     responseData.data = '';

+ 2 - 2
app/controller/sign_controller.js

@@ -51,9 +51,9 @@ module.exports = app => {
             try {
                 const stream = await ctx.getFileStream({ requireFile: false });
                 const create_time = Date.parse(new Date()) / 1000;
-                const dirName = 'app/public/upload/sign/';
+                const dirName = '/upload/sign/';
                 const fileName = moment().format('YYYYMMDD') + '_sign_' + create_time + '.png';
-                await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
                 await sendToWormhole(stream);
 
                 const result = await ctx.service.projectAccount.update({ sign_path: fileName }, { id: stream.fields.id });

+ 20 - 20
app/controller/stage_controller.js

@@ -570,8 +570,8 @@ module.exports = app => {
                 const stream = await ctx.getFileStream();
                 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, 'app', fileName));
+                const fileName = path.join('upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + fileInfo.ext);
+                await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, fileName));
                 ctx.body = {err: 0, msg: '', data: fileName};
             } catch(err) {
                 this.log(err);
@@ -592,10 +592,10 @@ module.exports = app => {
 
                 if (data.updateType === 'update') {
                     const create_time = Date.parse(new Date()) / 1000;
-                    const fileName = path.join('public/upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + '.jpg');
+                    const fileName = path.join('upload', this.ctx.tender.id.toString(), 'im', 'calcImg_' + create_time + '.jpg');
                     const base64Data = data.img.replace(/^data:image\/\w+;base64,/, "");
                     const dataBuffer = new Buffer(base64Data, 'base64');
-                    await this.ctx.helper.saveBufferFile(dataBuffer, path.join(this.app.baseDir, 'app', fileName));
+                    await this.ctx.helper.saveBufferFile(dataBuffer, path.join(this.app.config.filePath, fileName));
                     data.calc_img = fileName;
                     data.calc_img_org = JSON.stringify(data.imgInfo);
                     delete data.updateType;
@@ -1191,17 +1191,17 @@ module.exports = app => {
                     if (!stream.filename) {
                         throw '请选择上传的文件!';
                     }
-                    const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
+                    const dirName = '/upload/stage/' + moment().format('YYYYMMDD');
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
+                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.config.filePath, 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.baseDir, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
 
                     if (stream) {
                         await sendToWormhole(stream);
@@ -1251,7 +1251,7 @@ module.exports = app => {
                 try {
                     const fileInfo = await ctx.service.stageAtt.getDataById(id);
                     if (fileInfo !== undefined && fileInfo !== '') {
-                        const fileName = path.join(this.app.baseDir, fileInfo.filepath);
+                        const fileName = path.join(this.app.config.filePath, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -1297,7 +1297,7 @@ module.exports = app => {
                 const fileInfo = await ctx.service.stageAtt.getDataById(data.id);
                 if (fileInfo !== undefined && fileInfo !== '') {
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.config.filePath, fileInfo.filepath));
                     // 再删除数据库
                     await ctx.service.stageAtt.deleteById(data.id);
                     responseData.data = '';
@@ -1338,15 +1338,15 @@ module.exports = app => {
                 if (stream.filename !== undefined) {
                     const create_time = Date.parse(new Date()) / 1000;
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = 'app/public/upload/stage/' + moment().format('YYYYMMDD');
+                    const dirName = '/upload/stage/' + moment().format('YYYYMMDD');
                     const fileName = 'stage' + create_time + fileInfo.ext;
 
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
+                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
                     // 保存数据到att表
                     fileData = {
                         filesize: stream.fields.size,
@@ -1398,15 +1398,15 @@ module.exports = app => {
                         throw '请选择上传的文件!';
                     }
                     const fileInfo = path.parse(stream.filename);
-                    const dirName = 'app/public/upload/pay/' + moment().format('YYYYMMDD');
+                    const dirName = '/upload/pay/' + moment().format('YYYYMMDD');
                     const fileName = 'pay' + create_time + '_' + index + fileInfo.ext;
 
                     // 判断文件夹是否存在,不存在则直接创建文件夹
-                    if (!fs.existsSync(path.join(this.app.baseDir, dirName))) {
-                        await fs.mkdirSync(path.join(this.app.baseDir, dirName));
+                    if (!fs.existsSync(path.join(this.app.config.filePath, dirName))) {
+                        await fs.mkdirSync(path.join(this.app.config.filePath, dirName));
                     }
                     // 保存文件
-                    await ctx.helper.saveStreamFile(stream, path.join(this.app.baseDir, dirName, fileName));
+                    await ctx.helper.saveStreamFile(stream, path.join(this.app.config.filePath, dirName, fileName));
                     await sendToWormhole(stream);
                     // 插入到stage_pay对应的附件列表中
                     const attData = {
@@ -1453,7 +1453,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.baseDir, fileInfo.filepath);
+                        const fileName = path.join(this.app.config.filePath, fileInfo.filepath);
                         // 解决中文无法下载问题
                         const userAgent = (ctx.request.header['user-agent'] || '').toLowerCase();
                         let disposition = '';
@@ -1500,7 +1500,7 @@ module.exports = app => {
                 if (payInfo !== undefined) {
                     const fileInfo = JSON.parse(payInfo.attachment)[data.index];
                     // 先删除文件
-                    await fs.unlinkSync(path.join(this.app.baseDir, fileInfo.filepath));
+                    await fs.unlinkSync(path.join(this.app.config.filePath, 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.baseDir, att.filepath));
+                        await fs.unlinkSync(path.join(this.app.config.filePath, 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.baseDir, pat.filepath))) {
-                                    await fs.unlinkSync(path.join(this.app.baseDir, pat.filepath));
+                                if (fs.existsSync(path.join(this.app.config.filePath, pat.filepath))) {
+                                    await fs.unlinkSync(path.join(this.app.config.filePath, 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.baseDir, att.filepath))) {
-                            await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                        if (fs.existsSync(path.join(this.app.config.filePath, att.filepath))) {
+                            await fs.unlinkSync(path.join(this.app.config.filePath, 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.baseDir, att.filepath))) {
-                            await fs.unlinkSync(path.join(this.app.baseDir, att.filepath));
+                        if (fs.existsSync(path.join(this.app.config.filePath, att.filepath))) {
+                            await fs.unlinkSync(path.join(this.app.config.filePath, att.filepath));
                         }
                     }
                 }