u
This commit is contained in:
		
						commit
						97563fdf30
					
				
							
								
								
									
										17
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| .DS_Store | ||||
| node_modules/ | ||||
| npm-debug.log* | ||||
| yarn-debug.log* | ||||
| yarn-error.log* | ||||
| /test/unit/coverage/ | ||||
| /test/e2e/reports/ | ||||
| selenium-debug.log | ||||
| 
 | ||||
| # Editor directories and files | ||||
| .idea | ||||
| .vscode | ||||
| *.suo | ||||
| *.ntvs* | ||||
| *.njsproj | ||||
| *.sln | ||||
| /package-lock.json | ||||
							
								
								
									
										16
									
								
								.prettierrc.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								.prettierrc.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| /*  | ||||
| 对 VSCode Prettier 有效;建议一直要有本配置文件,否则不同版本的 Prettier 的默认配置会不同,例如 TrailingComma | ||||
| 对 VSCode Prettier Standard 无效,似乎是集成了不能修改的配置。 | ||||
| */ | ||||
| module.exports = { | ||||
|   printWidth: 160, // default 80
 | ||||
|   tabWidth: 2, // default 2
 | ||||
|   useTabs: false, | ||||
|   semi: false, // default true
 | ||||
|   singleQuote: true, // default false
 | ||||
|   trailingComma: 'es5', // none (default in v 1.*), es5 (default in v2.0.0), all
 | ||||
|   bracketSpacing: true, // default true
 | ||||
|   jsxBracketSameLine: false, // default false
 | ||||
|   arrowParens: 'always', // avoid (default in v1.9.0), always (default since v2.0.0)
 | ||||
|   quoteProps: 'as-needed', // as-needed (default), consistent, preserve
 | ||||
| } | ||||
							
								
								
									
										39
									
								
								index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| const multer = require('multer') | ||||
| const path = require('path') | ||||
| const crypto = require('crypto') | ||||
| const wo = global.wo | ||||
| 
 | ||||
| module.exports = { | ||||
| 
 | ||||
|   MulterStore: multer({ | ||||
|     // dest:'./File/', // 这样,不能自定义文件名。
 | ||||
|     storage: Multer.diskStorage({ | ||||
|       destination (req, file, cb) { | ||||
|         // 如果直接提供字符串,Multer会负责创建该目录。如果提供函数,你要负责确保该目录存在。
 | ||||
|         const folder = wo?.envi?.uploadroot // 目录是相对于本应用的入口js的,即相对于 server.js 的位置。
 | ||||
|         cb(null, folder) | ||||
|       }, | ||||
|       filename (req, file, cb) { | ||||
|         // 注意,req.body 也许还没有信息,因为这取决于客户端发送body和file的顺序。必要的信息请从 req.headers 传递。
 | ||||
|         const fileNameExtension = path.extname(file.originalname) | ||||
|         const filename = `${Date.now()}_${crypto.randomBytes(32).toString('hex')}${fileNameExtension}` | ||||
|         cb(null, filename) | ||||
|       }, | ||||
|     }), | ||||
|     // fileFilter:function(req, file, cb) {},
 | ||||
|     limits: { fileSize: 10485760 }, | ||||
|   }).single('file'), | ||||
| 
 | ||||
|   api: { | ||||
|     receiveFile () { | ||||
|       const file = wo._req?.file | ||||
|       if (file?.path) { | ||||
|         file.path = file.path.replace('\\', '/') | ||||
|         return Object.assign(file, { _state: 'SUCCESS' }) | ||||
|       } else { | ||||
|         return { _state: 'BACKEND_FAIL_FILE_NOT_RECEIVED' } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										13
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| { | ||||
|   "name": "base.FileTransfer.server", | ||||
|   "version": "0.1.0", | ||||
|   "private": true, | ||||
|   "dependencies": { | ||||
|     "multer": "^1.4.3" | ||||
|   }, | ||||
|   "devDependencies": {}, | ||||
|   "scripts": { | ||||
|     "setup": "npm install" | ||||
|   }, | ||||
|   "author": "" | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user