@unavatar/core 3.45.21 → 3.45.23
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 +2 -2
- package/src/index.js +1 -0
- package/src/providers/duckduckgo.js +33 -3
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.45.
|
|
5
|
+
"version": "3.45.23",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"@metascraper/helpers": "~5.51.1",
|
|
129
129
|
"@microlink/mql": "~0.17.0",
|
|
130
130
|
"@microlink/ping-url": "~1.4.16",
|
|
131
|
-
"browserless": "~13.
|
|
131
|
+
"browserless": "~13.6.0",
|
|
132
132
|
"cacheable-lookup": "~6.1.0",
|
|
133
133
|
"data-uri-regex": "~0.1.4",
|
|
134
134
|
"debug-logfmt": "~1.4.10",
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const getAvatarUrl = host => `https://icons.duckduckgo.com/ip3/${host}.ico`
|
|
4
|
+
|
|
5
|
+
// DuckDuckGo's icon service is keyed by exact hostname and normalizes
|
|
6
|
+
// www <-> apex only for popular domains. Smaller sites are indexed under the
|
|
7
|
+
// single host their crawler saw (usually the canonical `www.` redirect target),
|
|
8
|
+
// so the other variant 404s. Toggle the prefix to recover it.
|
|
9
|
+
const toggleWww = host =>
|
|
10
|
+
host.startsWith('www.') ? host.slice(4) : `www.${host}`
|
|
11
|
+
|
|
12
|
+
module.exports = ({ reachableUrl }) => {
|
|
13
|
+
const isReachable = async url => {
|
|
14
|
+
try {
|
|
15
|
+
const { statusCode } = await reachableUrl(url)
|
|
16
|
+
return reachableUrl.isReachable({ statusCode })
|
|
17
|
+
} catch {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
6
20
|
}
|
|
21
|
+
|
|
22
|
+
return async function duckduckgo (input) {
|
|
23
|
+
const primary = getAvatarUrl(input)
|
|
24
|
+
if (await isReachable(primary)) return primary
|
|
25
|
+
|
|
26
|
+
const alternate = getAvatarUrl(toggleWww(input))
|
|
27
|
+
if (alternate !== primary && (await isReachable(alternate))) {
|
|
28
|
+
return alternate
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return primary
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
36
|
+
module.exports.toggleWww = toggleWww
|