add decorator for rate limit
This commit is contained in:
parent
c1946bbe7d
commit
6763b26b12
@ -15,6 +15,8 @@ export class RouterMap {
|
||||
permissions?: string[][]
|
||||
data?: RouterData[]
|
||||
depts?: string[]
|
||||
limit?: any
|
||||
limitMethod?: Function
|
||||
}
|
||||
> = new Map()
|
||||
}
|
||||
@ -140,3 +142,25 @@ export function dept(depts?: string | string[]) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要限流
|
||||
* 使用 @fastify/rate-limit
|
||||
*/
|
||||
export function limit(opt?: any) {
|
||||
return (target: BaseController, name: string, value: PropertyDescriptor) => {
|
||||
// @ts-ignore
|
||||
const key = target[name]
|
||||
let limitObj = { limit: opt || true }
|
||||
if (RouterMap.decoratedRouters.has(key)) {
|
||||
let objCurrent = RouterMap.decoratedRouters.get(key)
|
||||
Object.assign(objCurrent, limitObj)
|
||||
// @ts-ignore
|
||||
RouterMap.decoratedRouters.set(target[name], objCurrent)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
RouterMap.decoratedRouters.set(target[name], limitObj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user