| 
						
						
							
								
							
						
						
					 | 
					@ -5,235 +5,295 @@ const path = require('path') | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const fs = require('fs'); | 
					 | 
					 | 
					const fs = require('fs'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const OSS = require('ali-oss'); | 
					 | 
					 | 
					const OSS = require('ali-oss'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const uuid = require('uuid'); | 
					 | 
					 | 
					const uuid = require('uuid'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					const JSZip = require('jszip'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const UploadPath = { | 
					 | 
					 | 
					const UploadPath = { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], | 
					 | 
					 | 
					   project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    report: ['.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf'], | 
					 | 
					 | 
					   report: ['.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf'], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    data: ['.txt', '.xls', '.xlsx', ".csv"], | 
					 | 
					 | 
					   data: ['.txt', '.xls', '.xlsx', ".csv"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    image: ['.png', '.jpg', '.svg'], | 
					 | 
					 | 
					   image: ['.png', '.jpg', '.svg'], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    three: ['.js'], | 
					 | 
					 | 
					   three: ['.js'], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    video: ['.mp4'] | 
					 | 
					 | 
					   video: ['.mp4'] | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					}; | 
					 | 
					 | 
					}; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					const ext = { | 
					 | 
					 | 
					const ext = { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.gif', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], | 
					 | 
					 | 
					   project: ['.txt', '.dwg', '.doc', '.docx', '.xls', '.xlsx', ".csv", '.pdf', '.pptx', '.png', '.jpg', '.gif', '.svg', '.rar', '.zip', '.jpeg', '.mp4'], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    report: [".doc", ".docx", ".xls", ".xlsx", ".pdf"], | 
					 | 
					 | 
					   report: [".doc", ".docx", ".xls", ".xlsx", ".pdf"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    data: [".txt", ".xls", ".xlsx"], | 
					 | 
					 | 
					   data: [".txt", ".xls", ".xlsx"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    image: [".png", ".jpg", ".svg"], | 
					 | 
					 | 
					   image: [".png", ".jpg", ".svg"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    three: [".js"], | 
					 | 
					 | 
					   three: [".js"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    video: [".mp4"], | 
					 | 
					 | 
					   video: [".mp4"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    bpmn: [".bpmn", ".bpmn20.xml", ".zip", ".bar"], | 
					 | 
					 | 
					   bpmn: [".bpmn", ".bpmn20.xml", ".zip", ".bar"], | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    app: [".apk"] | 
					 | 
					 | 
					   app: [".apk"] | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					module.exports = { | 
					 | 
					 | 
					module.exports = { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    entry: function (app, router, opts) { | 
					 | 
					 | 
					   entry: function (app, router, opts) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        let download_ = async function (ctx, next) { | 
					 | 
					 | 
					      let download_ = async function (ctx, next) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            const { fetchUrl } = opts.qiniu; | 
					 | 
					 | 
					         const { fetchUrl } = opts.qiniu; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            const { fetchUrl: aliFetchUrl, bucket, region } = opts.aliOss | 
					 | 
					 | 
					         const { fetchUrl: aliFetchUrl, bucket, region } = opts.aliOss | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if (ctx.path && ctx.path.includes(fetchUrl)) { | 
					 | 
					 | 
					         if (ctx.path && ctx.path.includes(fetchUrl)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					                try { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    const { filename } = ctx.request.query; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    const fkey = decodeURI(ctx.path.slice(fetchUrl.length + 1)).replace(/\.json$/, '.js'); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    if (ctx.path) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        const extNames = ctx.path.split('.'); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        app.fs.logger.log('info', 'extNames', extNames); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        if (extNames.length > 0) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            let fileType = extNames[extNames.length - 1].toLowerCase(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            if (fileType === 'pdf') { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                                ctx.type = 'application/pdf'; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                                app.fs.logger.log('info', 'application/pdf', fileType); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    const publicDownloadUrl = await app.fs.attachment.download(fkey); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ctx.status = 200; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    if (filename) ctx.attachment(filename); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ctx.body = request.get(publicDownloadUrl); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                } catch (err) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ctx.fs.logger.error(err); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ctx.status = 404; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ctx.body = { error: 'file not found.' }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } else if (ctx.path && ctx.path.includes(aliFetchUrl)) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                const { filename } = ctx.request.query; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                const fkey = decodeURI(ctx.path.slice(aliFetchUrl.length + 1)).replace(/\.json$/, '.js'); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if (ctx.path) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    const extNames = ctx.path.split('.'); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    app.fs.logger.log('info', 'extNames', extNames); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    if (extNames.length > 0) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        let fileType = extNames[extNames.length - 1].toLowerCase(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        if (fileType === 'pdf') { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            ctx.type = 'application/pdf'; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            app.fs.logger.log('info', 'application/pdf', fileType); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                const publicDownloadUrl = `http://${bucket}.${region}.aliyuncs.com/${encodeURIComponent(fkey)}` | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.status = 200; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = request.get(publicDownloadUrl); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } else { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                await next(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        let upload = async function (ctx, next) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            try { | 
					 | 
					 | 
					            try { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { files } = await parse(ctx.req); | 
					 | 
					 | 
					               const { filename } = ctx.request.query; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const file = files[0]; | 
					 | 
					 | 
					               const fkey = decodeURI(ctx.path.slice(fetchUrl.length + 1)).replace(/\.json$/, '.js'); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const extname = path.extname(file.filename).toLowerCase(); | 
					 | 
					 | 
					               if (ctx.path) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const fileType = ctx.query.type || "image"; | 
					 | 
					 | 
					                  const extNames = ctx.path.split('.'); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const fileFolder = ctx.query.fileFolder || 'common'; | 
					 | 
					 | 
					                  app.fs.logger.log('info', 'extNames', extNames); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if (ext[fileType].indexOf(extname) < 0) { | 
					 | 
					 | 
					                  if (extNames.length > 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.status = 400; | 
					 | 
					 | 
					                     let fileType = extNames[extNames.length - 1].toLowerCase(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.body = JSON.stringify({ name: 'UploadFailed', message: '文件格式无效' }); | 
					 | 
					 | 
					                     if (fileType === 'pdf') { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    return; | 
					 | 
					 | 
					                        ctx.type = 'application/pdf'; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } | 
					 | 
					 | 
					                        app.fs.logger.log('info', 'application/pdf', fileType); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const date = new Date().toLocaleDateString(); | 
					 | 
					 | 
					                     } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const time = new Date().getTime(); | 
					 | 
					 | 
					                  } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                let fileName = time + '_' + file.filename; | 
					 | 
					 | 
					               } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName); | 
					 | 
					 | 
					               const publicDownloadUrl = await app.fs.attachment.download(fkey); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const pathUrl = `./client/assets/files/${fileFolder}`; | 
					 | 
					 | 
					               ctx.status = 200; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					               if (filename) ctx.attachment(filename); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const res1 = fs.existsSync(`./client/assets/files/${fileFolder}`); | 
					 | 
					 | 
					               ctx.body = request.get(publicDownloadUrl); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					                !res1 && fs.mkdirSync(`./client/assets/files/${fileFolder}`); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                const res = fs.existsSync(pathUrl); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                !res && fs.mkdirSync(pathUrl); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                let stream = fs.createWriteStream(saveFile); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                fs.createReadStream(file.path).pipe(stream); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                stream.on('error', function (err) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    app.fs.logger.log('error', '[Upload Heatmap]', err); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                }); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.status = 200; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = { filename: path.join(`/assets/files/${fileFolder}`, fileName), name: 'UploadSuccess', message: '上传成功' }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            } catch (err) { | 
					 | 
					 | 
					            } catch (err) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.status = 500; | 
					 | 
					 | 
					               ctx.fs.logger.error(err); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.fs.logger.error(err); | 
					 | 
					 | 
					               ctx.status = 404; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.body = { err: 'upload error.' }; | 
					 | 
					 | 
					               ctx.body = { error: 'file not found.' }; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } else if (ctx.path && ctx.path.includes(aliFetchUrl)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const { filename } = ctx.request.query; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const fkey = decodeURI(ctx.path.slice(aliFetchUrl.length + 1)).replace(/\.json$/, '.js'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            if (ctx.path) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               const extNames = ctx.path.split('.'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               app.fs.logger.log('info', 'extNames', extNames); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               if (extNames.length > 0) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  let fileType = extNames[extNames.length - 1].toLowerCase(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  if (fileType === 'pdf') { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                     ctx.type = 'application/pdf'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                     app.fs.logger.log('info', 'application/pdf', fileType); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } | 
					 | 
					 | 
					            const publicDownloadUrl = `http://${bucket}.${region}.aliyuncs.com/${encodeURIComponent(fkey)}` | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = request.get(publicDownloadUrl); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } else { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            await next(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        let remove = async function (ctx, next) { | 
					 | 
					 | 
					      let upload = async function (ctx, next) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            try { | 
					 | 
					 | 
					         try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const fkeys = ctx.request.body; | 
					 | 
					 | 
					            const { files } = await parse(ctx.req); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                let removeUrl = path.join(__dirname, '../../', './client', fkeys.url); | 
					 | 
					 | 
					            const file = files[0]; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const res = fs.existsSync(removeUrl); | 
					 | 
					 | 
					            const extname = path.extname(file.filename).toLowerCase(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if (!res) { | 
					 | 
					 | 
					            const fileType = ctx.query.type || "image"; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.status = 400; | 
					 | 
					 | 
					            const fileFolder = ctx.query.fileFolder || 'common'; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.body = JSON.stringify({ name: 'DeleteFailed', message: '文件地址不存在' }); | 
					 | 
					 | 
					            if (ext[fileType].indexOf(extname) < 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    return; | 
					 | 
					 | 
					               ctx.status = 400; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } | 
					 | 
					 | 
					               ctx.body = JSON.stringify({ name: 'UploadFailed', message: '文件格式无效' }); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                fs.unlink(removeUrl, function (error) { | 
					 | 
					 | 
					               return; | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					                    if (error) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        console.log(error); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                }) | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.status = 200; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = { name: 'DeleteSuccess.', message: '删除成功' }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } catch (err) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.status = 500; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.fs.logger.error(err); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = { err: 'upload cleanup error.' }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } | 
					 | 
					 | 
					            const date = new Date().toLocaleDateString(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        let upload_ = async function (ctx, next) { | 
					 | 
					 | 
					            const time = new Date().getTime(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            let fkey = null; | 
					 | 
					 | 
					            let fileName = time + '_' + file.filename; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            try { | 
					 | 
					 | 
					            let saveFile = path.join(__dirname, '../../', `/client/assets/files/${fileFolder}`, fileName); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { p } = ctx.params; | 
					 | 
					 | 
					            const pathUrl = `./client/assets/files/${fileFolder}`; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { files } = await parse(ctx.req); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const file = files[0]; | 
					 | 
					 | 
					            const res1 = fs.existsSync(`./client/assets/files/${fileFolder}`); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const extname = path.extname(file.filename).toLowerCase(); | 
					 | 
					 | 
					            !res1 && fs.mkdirSync(`./client/assets/files/${fileFolder}`); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if (!UploadPath[p]) { | 
					 | 
					 | 
					            const res = fs.existsSync(pathUrl); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.status = 400; | 
					 | 
					 | 
					            !res && fs.mkdirSync(pathUrl); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.body = JSON.stringify({ error: '附件存放的文件夹名称无效' }); | 
					 | 
					 | 
					            let stream = fs.createWriteStream(saveFile); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    return; | 
					 | 
					 | 
					            fs.createReadStream(file.path).pipe(stream); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } else if (UploadPath[p].indexOf(extname) < 0) { | 
					 | 
					 | 
					            stream.on('error', function (err) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.status = 400; | 
					 | 
					 | 
					               app.fs.logger.log('error', '[Upload Heatmap]', err); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.body = JSON.stringify({ error: '文件格式无效' }); | 
					 | 
					 | 
					            }); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    return; | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } else { | 
					 | 
					 | 
					            ctx.body = { filename: path.join(`/assets/files/${fileFolder}`, fileName), name: 'UploadSuccess', message: '上传成功' }; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    const fileInfo = await ctx.app.fs.attachment.upload(file, { uploadPath: p }); | 
					 | 
					 | 
					         } catch (err) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    fkey = fileInfo.key; | 
					 | 
					 | 
					            ctx.status = 500; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    ctx.body = { uploaded: fkey }; | 
					 | 
					 | 
					            ctx.fs.logger.error(err); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                } | 
					 | 
					 | 
					            ctx.body = { err: 'upload error.' }; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            } catch (err) { | 
					 | 
					 | 
					         } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.status = 500; | 
					 | 
					 | 
					      } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.fs.logger.error(err); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.body = { err: 'upload error.' }; | 
					 | 
					 | 
					      let remove = async function (ctx, next) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const fkeys = ctx.request.body; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            let removeUrl = path.join(__dirname, '../../', './client', fkeys.url); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const res = fs.existsSync(removeUrl); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            if (!res) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.status = 400; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.body = JSON.stringify({ name: 'DeleteFailed', message: '文件地址不存在' }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } | 
					 | 
					 | 
					            fs.unlink(removeUrl, function (error) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               if (error) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  console.log(error); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            }) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = { name: 'DeleteSuccess.', message: '删除成功' }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } catch (err) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 500; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.fs.logger.error(err); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = { err: 'upload cleanup error.' }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      let upload_ = async function (ctx, next) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         let fkey = null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const { p } = ctx.params; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const { files } = await parse(ctx.req); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const file = files[0]; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const extname = path.extname(file.filename).toLowerCase(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            if (!UploadPath[p]) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.status = 400; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.body = JSON.stringify({ error: '附件存放的文件夹名称无效' }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } else if (UploadPath[p].indexOf(extname) < 0) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.status = 400; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.body = JSON.stringify({ error: '文件格式无效' }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } else { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               const fileInfo = await ctx.app.fs.attachment.upload(file, { uploadPath: p }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               fkey = fileInfo.key; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               ctx.body = { uploaded: fkey }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } catch (err) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 500; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.fs.logger.error(err); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = { err: 'upload error.' }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        const uploadAliOSS = async (ctx,) => { | 
					 | 
					 | 
					      const uploadAliOSS = async (ctx,) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            // 这个是上传到阿里
 | 
					 | 
					 | 
					         // 这个是上传到阿里
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            try { | 
					 | 
					 | 
					         try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { aliOss } = opts | 
					 | 
					 | 
					            const { aliOss } = opts | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { p = 'default' } = ctx.params; | 
					 | 
					 | 
					            const { p = 'default' } = ctx.params; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { files } = await parse(ctx.req); | 
					 | 
					 | 
					            const { files } = await parse(ctx.req); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const file = files[0]; | 
					 | 
					 | 
					            const file = files[0]; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const filename = file.filename || path.basename(file); | 
					 | 
					 | 
					            const filename = file.filename || path.basename(file); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const client = new OSS({ | 
					 | 
					 | 
					            const client = new OSS({ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou.
 | 
					 | 
					 | 
					               // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou.
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    region: aliOss.region, | 
					 | 
					 | 
					               region: aliOss.region, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户.
 | 
					 | 
					 | 
					               // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户.
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    accessKeyId: aliOss.accessKey, | 
					 | 
					 | 
					               accessKeyId: aliOss.accessKey, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    accessKeySecret: aliOss.secretKey, | 
					 | 
					 | 
					               accessKeySecret: aliOss.secretKey, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // 填写Bucket名称,例如examplebucket.
 | 
					 | 
					 | 
					               // 填写Bucket名称,例如examplebucket.
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    bucket: aliOss.bucket, | 
					 | 
					 | 
					               bucket: aliOss.bucket, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                }); | 
					 | 
					 | 
					            }); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                let uploadPath = path.posix.join(p, uuid.v4(), filename); | 
					 | 
					 | 
					            let uploadPath = path.posix.join(p, uuid.v4(), filename); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                let result = await client.putStream( | 
					 | 
					 | 
					            let result = await client.putStream( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    uploadPath, | 
					 | 
					 | 
					               uploadPath, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    file, | 
					 | 
					 | 
					               file, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // { contentLength: size }
 | 
					 | 
					 | 
					               // { contentLength: size }
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ); | 
					 | 
					 | 
					            ); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.status = 200; | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.body = { | 
					 | 
					 | 
					            ctx.body = { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    key: result.name, | 
					 | 
					 | 
					               key: result.name, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    uploaded: result.name, | 
					 | 
					 | 
					               uploaded: result.name, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    url: result.url, | 
					 | 
					 | 
					               url: result.url, | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                }; | 
					 | 
					 | 
					            }; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            } catch (error) { | 
					 | 
					 | 
					         } catch (error) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.status = 400; | 
					 | 
					 | 
					            ctx.status = 400; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.fs.logger.error(error); | 
					 | 
					 | 
					            ctx.fs.logger.error(error); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.body = { err: 'upload error.' }; | 
					 | 
					 | 
					            ctx.body = { err: 'upload error.' }; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      const downloadFromAli = async (ctx) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const { aliOss } = opts | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const { path, filename } = ctx.query | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const client = new OSS({ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou.
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               region: aliOss.region, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户.
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               accessKeyId: aliOss.accessKey, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               accessKeySecret: aliOss.secretKey, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               // 填写Bucket名称,例如examplebucket.
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               bucket: aliOss.bucket, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const filename_ = filename || path.split('/').pop() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            const result = await client.get(path); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.set('Content-Type', 'application/x-xls'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.set('Content-disposition', 'attachment; filename=' + filename_); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = result.content; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } catch (error) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 400; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.fs.logger.error(error); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = { err: 'download error.' }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      const getFileBlob = (url) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         return new Promise((resolve, reject) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            let request = new XMLHttpRequest() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            request.open("GET", url, true) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            request.responseType = "blob" | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            request.onload = (res) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               if (res.target.status == 200) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  resolve(res.target.response) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               } else { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                  reject(res) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					               } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } | 
					 | 
					 | 
					            request.send() | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         }) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        const downloadFromAli = async (ctx) => { | 
					 | 
					 | 
					      const packBulk = async (ctx) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            try { | 
					 | 
					 | 
					         console.log(11111,); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { aliOss } = opts | 
					 | 
					 | 
					         try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const { path, filename } = ctx.query | 
					 | 
					 | 
					            const { fileUrl, folderId } = parse(ctx.req) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const client = new OSS({ | 
					 | 
					 | 
					            const zip = new JSZip() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // yourRegion填写Bucket所在地域.以华东1(杭州)为例,Region填写为oss-cn-hangzhou.
 | 
					 | 
					 | 
					            let result = [] | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    region: aliOss.region, | 
					 | 
					 | 
					            let files = [] | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // 阿里云账号AccessKey拥有所有API的访问权限,风险很高.强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户.
 | 
					 | 
					 | 
					            console.log(22,fileUrl); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    accessKeyId: aliOss.accessKey, | 
					 | 
					 | 
					            fileUrl.map(a => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    accessKeySecret: aliOss.secretKey, | 
					 | 
					 | 
					            let url = path.join(__dirname, '../../', './client', a); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    // 填写Bucket名称,例如examplebucket.
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    bucket: aliOss.bucket, | 
					 | 
					 | 
					               files.push({ url, name: 111 }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                }); | 
					 | 
					 | 
					            }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					            for (let i in files) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const filename_ = filename || path.split('/').pop() | 
					 | 
					 | 
					               let promise = getFileBlob(files[i].url).then((res) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					                  let format = files[i].url.substring(files[i].url.lastIndexOf("."), files[i].url.length) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                const result = await client.get(path); | 
					 | 
					 | 
					                  zip.file(files[i].name + format, res, { binary: true }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.status = 200; | 
					 | 
					 | 
					               }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.set('Content-Type', 'application/x-xls'); | 
					 | 
					 | 
					               result.push(promise) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                ctx.set('Content-disposition', 'attachment; filename=' + filename_); | 
					 | 
					 | 
					               console.log(77, promise); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = result.content; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } catch (error) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.status = 400; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.fs.logger.error(error); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                ctx.body = { err: 'download error.' }; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } | 
					 | 
					 | 
					            console.log(33,); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.use(download_); | 
					 | 
					 | 
					            Promise.all(result).then(() => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.post('/_upload/new', upload); | 
					 | 
					 | 
					               zip.generateAsync({ type: "blob" }).then((res) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.delete('/_upload/cleanup', remove); | 
					 | 
					 | 
					                  console.log(55,); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.post('/_upload/attachments/ali/:p', uploadAliOSS); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.get('/_download/attachments/ali', downloadFromAli); | 
					 | 
					 | 
					                  saveAs(res, `${111}.zip`) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        router.post('/_upload/attachments/:p', upload_); | 
					 | 
					 | 
					               }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    } | 
					 | 
					 | 
					            }) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            console.log(44,); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 200; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = {}; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } catch (error) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.status = 400; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.fs.logger.error(error); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            ctx.body = { err: 'download error.' }; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					         } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.use(download_); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.post('/_upload/new', upload); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.delete('/_upload/cleanup', remove); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.post('/_upload/attachments/ali/:p', uploadAliOSS); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.get('/_download/attachments/ali', downloadFromAli); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.post('/_upload/attachments/:p', upload_); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					      router.post('/packBulk/:p', packBulk); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					   } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					}; | 
					 | 
					 | 
					}; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					
  |