odesli.js 1.3.5 → 1.3.6
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/.prettierignore +30 -30
- package/API_IMPROVEMENTS.md +16 -16
- package/LICENSE +14 -14
- package/README.md +465 -82
- package/RELEASE_NOTES_1.1.0.md +1 -1
- package/examples/README.md +281 -60
- package/examples/advanced-features-example.js +4 -4
- package/examples/advanced-usage.js +3 -3
- package/examples/basic-usage.js +4 -9
- package/examples/cache-test.js +1 -1
- package/examples/rate-limiter-strategies.js +83 -0
- package/examples/test-apple-music-extraction.js +1 -1
- package/examples/user-agent-example.js +1 -1
- package/lib/rate-limiter.js +16 -15
- package/package.json +13 -1
package/lib/rate-limiter.js
CHANGED
|
@@ -27,22 +27,23 @@ class RateLimiter {
|
|
|
27
27
|
* Most efficient for burst handling
|
|
28
28
|
*/
|
|
29
29
|
async tokenBucket() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.tokens
|
|
39
|
-
|
|
30
|
+
while (true) {
|
|
31
|
+
const now = Date.now()
|
|
32
|
+
const timePassed = now - this.lastRefill
|
|
33
|
+
const tokensToAdd = Math.floor(timePassed / this.windowMs) * this.maxRequests
|
|
34
|
+
|
|
35
|
+
this.tokens = Math.min(this.maxRequests, this.tokens + tokensToAdd)
|
|
36
|
+
this.lastRefill = now
|
|
37
|
+
|
|
38
|
+
if (this.tokens >= 1) {
|
|
39
|
+
this.tokens--
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Calculate wait time
|
|
44
|
+
const waitTime = this.windowMs - (timePassed % this.windowMs)
|
|
45
|
+
await new Promise(resolve => setTimeout(resolve, waitTime))
|
|
40
46
|
}
|
|
41
|
-
|
|
42
|
-
// Calculate wait time
|
|
43
|
-
const waitTime = this.windowMs - (timePassed % this.windowMs)
|
|
44
|
-
await new Promise(resolve => setTimeout(resolve, waitTime))
|
|
45
|
-
return this.tokenBucket()
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "odesli.js",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Node.js Client to query odesli.co (song.link/album.link) API",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
"types": "./lib/index.d.ts",
|
|
11
11
|
"import": "./lib/index.js",
|
|
12
12
|
"require": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./rate-limiter": {
|
|
15
|
+
"import": "./lib/rate-limiter.js",
|
|
16
|
+
"require": "./lib/rate-limiter.js"
|
|
17
|
+
},
|
|
18
|
+
"./metrics": {
|
|
19
|
+
"import": "./lib/metrics.js",
|
|
20
|
+
"require": "./lib/metrics.js"
|
|
21
|
+
},
|
|
22
|
+
"./plugin-system": {
|
|
23
|
+
"import": "./lib/plugin-system.js",
|
|
24
|
+
"require": "./lib/plugin-system.js"
|
|
13
25
|
}
|
|
14
26
|
},
|
|
15
27
|
"engines": {
|