File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11'use strict' ;
22
3- const { LinRouter } = require ( 'lin-mizar' ) ;
3+ const { LinRouter, NotFound } = require ( 'lin-mizar' ) ;
4+ const { ratelimit } = require ( 'lin-mizar/lin/limiter' ) ;
45const { LocalUploader } = require ( '../../extensions/file/local-uploader' ) ;
6+ const redis = require ( 'redis' ) ;
7+
8+ const client = redis . createClient ( ) ;
59
610const file = new LinRouter ( {
711 prefix : '/cms/file'
812} ) ;
913
1014file . post ( '/' , async ctx => {
1115 const files = await ctx . multipart ( ) ;
16+ if ( files . length < 1 ) {
17+ throw new NotFound ( { msg : '未找到符合条件的文件资源' } ) ;
18+ }
1219 const uploader = new LocalUploader ( 'app/assets' ) ;
1320 await uploader . upload ( files ) ;
1421 ctx . success ( ) ;
1522} ) ;
1623
24+ file . get (
25+ '/' ,
26+ ratelimit ( {
27+ db : client ,
28+ duration : 30 * 1000 ,
29+ max : 5 ,
30+ // throw: true,
31+ logging : true
32+ } ) ,
33+ async ctx => {
34+ ctx . body = {
35+ msg : 'just a normal response.'
36+ } ;
37+ }
38+ ) ;
39+
1740module . exports = { file } ;
Original file line number Diff line number Diff line change 3333 "jest" : " ^24.3.1" ,
3434 "nodemon" : " ^1.18.10" ,
3535 "prettier" : " 1.16.4" ,
36+ "redis" : " ^2.8.0" ,
3637 "supertest" : " ^3.4.2"
3738 },
3839 "dependencies" : {
You can’t perform that action at this time.
0 commit comments