@blocklet/rate-limit 1.16.45-beta-20250630-233332-04c2bd6f → 1.16.45-beta-20250702-072658-6f6c82be
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/lib/index.js +11 -2
- package/package.json +4 -3
package/lib/index.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.createRateLimiter = createRateLimiter;
|
|
|
12
12
|
const db_cache_1 = require("@abtnode/db-cache");
|
|
13
13
|
const express_rate_limit_1 = require("express-rate-limit");
|
|
14
14
|
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const md5_1 = __importDefault(require("@abtnode/util/lib/md5"));
|
|
15
16
|
/**
|
|
16
17
|
* Store for rate limit
|
|
17
18
|
*/
|
|
@@ -19,7 +20,7 @@ class RateLimitStore {
|
|
|
19
20
|
constructor(options) {
|
|
20
21
|
const serverUrls = (0, db_cache_1.getAbtNodeRedisAndSQLiteUrl)();
|
|
21
22
|
this.dbCache = new db_cache_1.DBCache(() => ({
|
|
22
|
-
prefix:
|
|
23
|
+
prefix: 'rate',
|
|
23
24
|
ttl: options.windowMs || 1000 * 60,
|
|
24
25
|
redisUrl: options.redisUrl || serverUrls.redisUrl,
|
|
25
26
|
sqlitePath: options.sqlitePath || serverUrls.sqlitePath || node_path_1.default.join(process.env.BLOCKLET_DATA_DIR, 'rate-limit.db'),
|
|
@@ -124,7 +125,15 @@ function createRateLimiter(options) {
|
|
|
124
125
|
windowMs: 1000 * 60,
|
|
125
126
|
limit: 10,
|
|
126
127
|
legacyHeaders: false,
|
|
127
|
-
keyGenerator: getIp,
|
|
128
128
|
...options,
|
|
129
|
+
keyGenerator: (req, res) => {
|
|
130
|
+
const key = options.keyGenerator ? options.keyGenerator(req, res) : getIp(req);
|
|
131
|
+
if (!key)
|
|
132
|
+
return null;
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
const did = req.getBlockletDid ? req.getBlockletDid() : 'blocklet';
|
|
135
|
+
const prefix = options.prefix || 'prefix';
|
|
136
|
+
return (0, md5_1.default)(`${did}:${prefix}:${key}`);
|
|
137
|
+
},
|
|
129
138
|
});
|
|
130
139
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.45-beta-
|
|
6
|
+
"version": "1.16.45-beta-20250702-072658-6f6c82be",
|
|
7
7
|
"description": "rate limit middleware",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"author": "blocklet<blocklet@arcblock.io>",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@abtnode/db-cache": "1.16.45-beta-
|
|
28
|
+
"@abtnode/db-cache": "1.16.45-beta-20250702-072658-6f6c82be",
|
|
29
|
+
"@abtnode/util": "1.16.45-beta-20250702-072658-6f6c82be",
|
|
29
30
|
"express-rate-limit": "^7.5.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"ts-node": "^10.9.1",
|
|
46
47
|
"typescript": "^5.6.3"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "e2b7203766cce76f547833530ac0eb463752162c"
|
|
49
50
|
}
|