-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rate limit and app version check for proxy commands.
- Loading branch information
1 parent
4719abc
commit fe7d405
Showing
11 changed files
with
137 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"id": "api_rate_limit", | ||
"type": "label", | ||
"label": { | ||
"en": "API rate limit", | ||
"de": "API Rate Limit", | ||
"nl": "API rate limiet" | ||
}, | ||
"hint": { | ||
"en": "This field shows the current rate limit usage. If it gets over 100%, the API will be blocked for a while until the average usage is below 100% again.", | ||
"de": "Dieses Feld zeigt die aktuelle API-Rate-Limit-Nutzung an. Wenn sie über 100% steigt, wird die API für eine Weile blockiert, bis die durchschnittliche Nutzung wieder unter 100% liegt.", | ||
"nl": "Dit veld toont het huidige gebruik van de tariefbeperking van de API. Als het boven de 100% komt, wordt de API een tijdje geblokkeerd totdat het gemiddelde gebruik weer onder de 100% ligt." | ||
}, | ||
"value": "0 %" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const CAPACITY = 60; // Allowed amound of API calls for the window | ||
const WINDOW_SIZE = 600; // Window size in seconds | ||
|
||
module.exports = class SlidingWindowLog { | ||
|
||
constructor(capacity = CAPACITY) { | ||
this.cache = []; | ||
this.capacity = capacity; | ||
} | ||
|
||
add() { | ||
this.cache.push(new Date()); | ||
this.refresh(); | ||
if (this.cache.length > this.capacity) { | ||
throw new Error('Rate limit exceeded'); | ||
} | ||
return true; | ||
} | ||
|
||
refresh() { | ||
let windowStart = new Date(Date.now() - WINDOW_SIZE * 1000); | ||
this.cache = this.cache.filter((timestamp) => timestamp > windowStart); | ||
} | ||
|
||
getState(){ | ||
return Math.round( this.cache.length * 100 / this.capacity ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters