mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Ready to implement API limit
This commit is contained in:
39
src/helpers/APILimitsHelper.ts
Normal file
39
src/helpers/APILimitsHelper.ts
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* API Limits helper
|
||||
*
|
||||
* This implementation of API limits stores
|
||||
* the counters inside memory, not in the databas
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
// Different supported actions
|
||||
export enum Action {
|
||||
LOGIN_FAILED = "login_failed",
|
||||
CREATE_ACCOUNT = "create_account"
|
||||
}
|
||||
|
||||
export class APILimitHelper {
|
||||
|
||||
/**
|
||||
* Trigger the counter (increase it by one)
|
||||
*
|
||||
* @param ip Target IP address
|
||||
* @param action The action to check
|
||||
*/
|
||||
public static async Trigger(ip: string, action: Action) {
|
||||
// TODO : trigger counter
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of actions perfomed by a user
|
||||
*
|
||||
* @param ip Target IP address
|
||||
* @param action The action to check
|
||||
*/
|
||||
public static async Count(ip: string, action: Action) : Promise<number> {
|
||||
// TODO : return count
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user