@20syldev/api 3.3.3 → 3.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/app.js +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://api.sylvain.pro"><img src="https://api.sylvain.pro/favicon.ico" alt="Logo" width="25%" height="auto"/></a>
|
|
3
3
|
|
|
4
4
|
# API Personnelle
|
|
5
|
-
[](https://github.com/20syldev/api/releases/latest)
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
8
|
---
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
## À propos de l'API
|
|
11
11
|
Voici mon API personnelle, disponible sur le domaine [api.sylvain.pro](https://api.sylvain.pro).
|
|
12
12
|
L'API est développée avec Node.js et hébergée **24h/7j**. Elle est **simple d'utilisation** et a une **documentation** disponible sur [docs.sylvain.pro](https://docs.sylvain.pro) !
|
|
13
|
-
> *Une limite de **
|
|
13
|
+
> *Une limite de **2000** requêtes **par heure** est fixée. Elle change pour certains endpoints nécessitant plus de ressources. Si vous souhaitez une **augmentation** de cette limite, n'hésitez pas à visiter la [documentation](https://docs.sylvain.pro/pricing).*
|
|
14
14
|
|
|
15
15
|
## Installer le paquet de l'API sur votre machine
|
|
16
16
|
```console
|
|
@@ -46,7 +46,7 @@ Enfin, **exécutez** le script de build, qui installera les **dépendances** et
|
|
|
46
46
|
$ npm run build
|
|
47
47
|
```
|
|
48
48
|
```console
|
|
49
|
-
> @20syldev/api@3.3.
|
|
49
|
+
> @20syldev/api@3.3.5 build
|
|
50
50
|
> npm install && node app.js
|
|
51
51
|
|
|
52
52
|
[...]
|
package/app.js
CHANGED
|
@@ -132,19 +132,26 @@ app.use((req, res, next) => {
|
|
|
132
132
|
else requestLimit = process.env.DEFAULT_LIMIT;
|
|
133
133
|
|
|
134
134
|
if (now > resetTime) requests = 0, resetTime = now + 3600000;
|
|
135
|
-
if (++requests > Math.max(process.env.GLOBAL_LIMIT
|
|
135
|
+
if (++requests > Math.max(process.env.GLOBAL_LIMIT, requestLimit)) {
|
|
136
136
|
return res.status(429).jsonResponse({ message: 'Too Many Requests' });
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
if (['__proto__', 'constructor', 'prototype'].includes(ip)) {
|
|
140
|
+
return res.status(400).jsonResponse({ message: 'Invalid IP address' });
|
|
141
|
+
}
|
|
142
|
+
|
|
139
143
|
if (!ipLimits[ip]) ipLimits[ip] = {};
|
|
140
144
|
if (!ipLimits[ip][hour]) ipLimits[ip][hour] = {};
|
|
141
145
|
ipLimits[ip][hour][minute] = (ipLimits[ip][hour][minute] || 0) + 1;
|
|
142
146
|
|
|
143
|
-
if (ipLimits[ip][hour][minute] > requestLimit)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
if (ipLimits[ip][hour][minute] > requestLimit) {
|
|
148
|
+
return res.status(429).jsonResponse({
|
|
149
|
+
message: 'Too Many Requests (IP limited), authenticate to increase the limit',
|
|
150
|
+
error: `You have exceeded the limit of ${requestLimit} requests per hour.`,
|
|
151
|
+
reset: `Reset in ${((resetTime - now) / 60000).toFixed(0)} minutes.`,
|
|
152
|
+
status: '429'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
148
155
|
|
|
149
156
|
Object.keys(ipLimits[ip]).forEach(h => { if (h != hour) delete ipLimits[ip][h]; });
|
|
150
157
|
|
package/package.json
CHANGED