@blocklet/rate-limit 1.16.46-beta-20250704-234926-09d872ad → 1.16.46-beta-20250708-074453-e1748586
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 +8 -0
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -65,6 +65,7 @@ class RateLimitStore {
|
|
|
65
65
|
if (!key)
|
|
66
66
|
return defaultLimitInfo;
|
|
67
67
|
try {
|
|
68
|
+
await this.dbCache.acquire(key);
|
|
68
69
|
let limitInfo = await this.get(key);
|
|
69
70
|
// reset row if expired
|
|
70
71
|
if (!limitInfo || limitInfo.resetTime.getTime() < Date.now()) {
|
|
@@ -80,11 +81,15 @@ class RateLimitStore {
|
|
|
80
81
|
console.error('[RateLimit] Error in increment:', error);
|
|
81
82
|
return defaultLimitInfo;
|
|
82
83
|
}
|
|
84
|
+
finally {
|
|
85
|
+
await this.dbCache.releaseLock(key);
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
async decrement(key) {
|
|
85
89
|
if (!key)
|
|
86
90
|
return;
|
|
87
91
|
try {
|
|
92
|
+
await this.dbCache.acquire(key);
|
|
88
93
|
const row = await this.get(key);
|
|
89
94
|
if (row) {
|
|
90
95
|
await this.set(key, {
|
|
@@ -96,6 +101,9 @@ class RateLimitStore {
|
|
|
96
101
|
catch (error) {
|
|
97
102
|
console.error('[RateLimit] Error in decrement:', error);
|
|
98
103
|
}
|
|
104
|
+
finally {
|
|
105
|
+
await this.dbCache.releaseLock(key);
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
async resetKey(key) {
|
|
101
109
|
try {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.46-beta-
|
|
6
|
+
"version": "1.16.46-beta-20250708-074453-e1748586",
|
|
7
7
|
"description": "rate limit middleware",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"author": "blocklet<blocklet@arcblock.io>",
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@abtnode/db-cache": "1.16.46-beta-
|
|
29
|
-
"@abtnode/util": "1.16.46-beta-
|
|
28
|
+
"@abtnode/db-cache": "1.16.46-beta-20250708-074453-e1748586",
|
|
29
|
+
"@abtnode/util": "1.16.46-beta-20250708-074453-e1748586",
|
|
30
30
|
"express-rate-limit": "^7.5.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"ts-node": "^10.9.1",
|
|
47
47
|
"typescript": "^5.6.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "1d2c430078b76a3f0da82dd708522dd5f6ce098c"
|
|
50
50
|
}
|