@unavatar/core 3.7.52 → 3.7.53
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/package.json +1 -1
- package/src/util/got.js +15 -7
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@unavatar/core",
|
|
3
3
|
"description": "Get unified user avatar from social networks, including Instagram, SoundCloud, Telegram, Twitter, YouTube & more.",
|
|
4
4
|
"homepage": "https://unavatar.io",
|
|
5
|
-
"version": "3.7.
|
|
5
|
+
"version": "3.7.53",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
package/src/util/got.js
CHANGED
|
@@ -7,14 +7,20 @@ const got = require('got')
|
|
|
7
7
|
|
|
8
8
|
const topUserAgents = require('top-user-agents')
|
|
9
9
|
const randomUserAgent = uniqueRandomArray(topUserAgents)
|
|
10
|
-
const precomputedUaHints = new Map(topUserAgents.map(userAgent => [userAgent, uaHints(userAgent)]))
|
|
11
10
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const precomputedUaHints = new Map(
|
|
12
|
+
topUserAgents.map(userAgent => [userAgent, uaHints(userAgent)])
|
|
13
|
+
)
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const precomputedUaHintEntries = new Map(
|
|
16
|
+
topUserAgents.map(userAgent => [
|
|
17
|
+
userAgent,
|
|
18
|
+
Object.entries(precomputedUaHints.get(userAgent))
|
|
19
|
+
])
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
const getUaHintEntries = userAgent =>
|
|
23
|
+
precomputedUaHintEntries.get(userAgent) || Object.entries(uaHints(userAgent))
|
|
18
24
|
|
|
19
25
|
const userAgentHook = options => {
|
|
20
26
|
let userAgent = options.headers['user-agent']
|
|
@@ -23,7 +29,9 @@ const userAgentHook = options => {
|
|
|
23
29
|
options.headers['user-agent'] = userAgent
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
|
|
32
|
+
const uaHintEntries = getUaHintEntries(userAgent)
|
|
33
|
+
for (let index = 0; index < uaHintEntries.length; index++) {
|
|
34
|
+
const [key, value] = uaHintEntries[index]
|
|
27
35
|
options.headers[key] = value
|
|
28
36
|
}
|
|
29
37
|
}
|