@unavatar/core 3.62.0 → 3.64.0
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/README.md +26 -3
- package/package.json +1 -1
- package/src/providers/duolingo.js +37 -0
- package/src/providers/gravatar.js +2 -0
- package/src/providers/index.js +5 -2
- package/src/providers/libravatar.js +53 -0
package/README.md
CHANGED
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
- [Domain](#domain)
|
|
43
43
|
- [Dribbble](#dribbble)
|
|
44
44
|
- [DuckDuckGo](#duckduckgo)
|
|
45
|
+
- [Duolingo](#duolingo)
|
|
45
46
|
- [Email](#email)
|
|
46
47
|
- [Facebook](#facebook)
|
|
47
48
|
- [Flickr](#flickr)
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
- [Keybase](#keybase)
|
|
61
62
|
- [Kick](#kick)
|
|
62
63
|
- [Ko-fi](#ko-fi)
|
|
64
|
+
- [Libravatar](#libravatar)
|
|
63
65
|
- [LinkedIn](#linkedin)
|
|
64
66
|
- [Mastodon](#mastodon)
|
|
65
67
|
- [Medium](#medium)
|
|
@@ -737,15 +739,21 @@ Get the favicon or logo for any domain via DuckDuckGo's icon service. Useful as
|
|
|
737
739
|
|
|
738
740
|
e.g., [unavatar.io/duckduckgo/microsoft.com](https://unavatar.io/duckduckgo/microsoft.com)
|
|
739
741
|
|
|
742
|
+
### Duolingo
|
|
743
|
+
|
|
744
|
+
Get any Duolingo learner's profile picture by their username.
|
|
745
|
+
|
|
746
|
+
e.g., [unavatar.io/duolingo/luis](https://unavatar.io/duolingo/luis)
|
|
747
|
+
|
|
740
748
|
### Email
|
|
741
749
|
|
|
742
|
-
Resolve user avatars from an email address with a single URL. The `/email/:key` route uses the same provider chain as a bare `/user@domain` path: the service tries Gravatar
|
|
750
|
+
Resolve user avatars from an email address with a single URL. The `/email/:key` route uses the same provider chain as a bare `/user@domain` path: the service tries Gravatar and GitHub, then Libravatar, then BIMI until one returns an image. No API keys and no SDK are required.
|
|
743
751
|
|
|
744
752
|
When the path looks like an email, unavatar walks that chain until a provider succeeds. You can also skip the chain and call a named email provider directly when you know where the avatar should come from.
|
|
745
753
|
|
|
746
754
|
Automatic resolution
|
|
747
755
|
|
|
748
|
-
Pass the address as the only path segment, or prefix it with `email/`. The API auto-detects email-shaped inputs and runs the same chain (Gravatar
|
|
756
|
+
Pass the address as the only path segment, or prefix it with `email/`. The API auto-detects email-shaped inputs and runs the same chain (Gravatar and GitHub, then Libravatar, then BIMI).
|
|
749
757
|
|
|
750
758
|
- Typed route `unavatar.io/email/{email}`: [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
|
|
751
759
|
- Bare path `unavatar.io/{email}`: [unavatar.io/hello@microlink.io](https://unavatar.io/hello@microlink.io)
|
|
@@ -756,6 +764,7 @@ Target a specific provider when you know where the avatar comes from.
|
|
|
756
764
|
|
|
757
765
|
- Gravatar (`unavatar.io/gravatar/{email-or-hash}`) — email is normalized and SHA-256 hashed; 64-hex SHA-256 or 32-hex MD5 passes through. Example: [unavatar.io/gravatar/hello@microlink.io](https://unavatar.io/gravatar/hello@microlink.io)
|
|
758
766
|
- GitHub (`unavatar.io/github/{email}`) — public profile email or commit history: [unavatar.io/github/sindresorhus@gmail.com](https://unavatar.io/github/sindresorhus@gmail.com)
|
|
767
|
+
- Libravatar (`unavatar.io/libravatar/{email-or-hash}`) — federated Gravatar alternative; follows the email domain's own avatar server when it publishes one: [unavatar.io/libravatar/francois@fmarier.org](https://unavatar.io/libravatar/francois@fmarier.org)
|
|
759
768
|
- BIMI (`unavatar.io/bimi/{email}`) — official brand logo from the address domain: [unavatar.io/bimi/support@ebay.com](https://unavatar.io/bimi/support@ebay.com)
|
|
760
769
|
|
|
761
770
|
e.g., [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
|
|
@@ -838,7 +847,7 @@ Available inputs:
|
|
|
838
847
|
|
|
839
848
|
When you pass an email address directly in the URL, it is visible in plain text — both in server logs and to any intermediary that inspects the request.
|
|
840
849
|
|
|
841
|
-
To avoid this, pass a pre-computed `MD5` or `SHA256` hash of the email instead. Unavatar detects the hash automatically and routes it to Gravatar, which natively
|
|
850
|
+
To avoid this, pass a pre-computed `MD5` or `SHA256` hash of the email instead. Unavatar detects the hash automatically and routes it to Gravatar, then Libravatar, which both natively support both hash formats.
|
|
842
851
|
|
|
843
852
|
### Gumroad
|
|
844
853
|
|
|
@@ -897,6 +906,20 @@ Get any Ko-fi page's profile picture by the creator username.
|
|
|
897
906
|
|
|
898
907
|
e.g., [unavatar.io/ko-fi/geekshock](https://unavatar.io/ko-fi/geekshock)
|
|
899
908
|
|
|
909
|
+
### Libravatar
|
|
910
|
+
|
|
911
|
+
Resolve avatars via [Libravatar](https://www.libravatar.org), the federated, open source alternative to Gravatar, using a plain email or a precomputed hash. Emails are trimmed, lowercased, and hashed with SHA-256; 64-hex SHA-256 and 32-hex MD5 values are passed through (normalized to lowercase).
|
|
912
|
+
|
|
913
|
+
Available inputs:
|
|
914
|
+
|
|
915
|
+
- Email address, e.g., [unavatar.io/libravatar/francois@fmarier.org](https://unavatar.io/libravatar/francois@fmarier.org)
|
|
916
|
+
- SHA-256 hash, e.g., [unavatar.io/libravatar/857915e8681217376523fa2c4653a499a7dc6826197b077d35fc029d7c38bda1](https://unavatar.io/libravatar/857915e8681217376523fa2c4653a499a7dc6826197b077d35fc029d7c38bda1)
|
|
917
|
+
- MD5 hash, e.g., [unavatar.io/libravatar/7cc352a2907216992f0f16d2af50b070](https://unavatar.io/libravatar/7cc352a2907216992f0f16d2af50b070)
|
|
918
|
+
|
|
919
|
+
When an email domain runs its own avatar server and publishes a `_avatars-sec._tcp` SRV record, the avatar is fetched from that server. Otherwise, and always for hashes, the central `seccdn.libravatar.org` server is used.
|
|
920
|
+
|
|
921
|
+
In the email chain, Libravatar runs only after Gravatar and GitHub miss, so it never overrides or slows down a Gravatar hit.
|
|
922
|
+
|
|
900
923
|
### LinkedIn
|
|
901
924
|
|
|
902
925
|
Get any LinkedIn user or company profile picture by username or company slug.
|
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.
|
|
5
|
+
"version": "3.64.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const stringify = require('../util/stringify')
|
|
4
|
+
|
|
5
|
+
const ORIGIN = 'https://www.duolingo.com'
|
|
6
|
+
const API_URL = `${ORIGIN}/2017-06-30/users`
|
|
7
|
+
const PICTURE_SIZE = 'xxlarge'
|
|
8
|
+
const DEFAULT_PICTURE_PATH_RE = /^\/avatar\/default_\d+\/?$/
|
|
9
|
+
|
|
10
|
+
const getAvatarUrl = input =>
|
|
11
|
+
`${API_URL}?${stringify({ username: input, fields: 'users{picture}' })}`
|
|
12
|
+
|
|
13
|
+
const getAvatar = body => {
|
|
14
|
+
const pic = body?.users?.[0]?.picture
|
|
15
|
+
if (typeof pic !== 'string' || !pic) return
|
|
16
|
+
|
|
17
|
+
const url = new URL(pic, ORIGIN)
|
|
18
|
+
if (DEFAULT_PICTURE_PATH_RE.test(url.pathname)) return
|
|
19
|
+
|
|
20
|
+
url.pathname = `${url.pathname.replace(/\/$/, '')}/${PICTURE_SIZE}`
|
|
21
|
+
return url.toString()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = ({ got }) =>
|
|
25
|
+
async function duolingo (input) {
|
|
26
|
+
const { body, statusCode } = await got(getAvatarUrl(input), {
|
|
27
|
+
responseType: 'json',
|
|
28
|
+
throwHttpErrors: false
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
if (statusCode >= 400) return
|
|
32
|
+
|
|
33
|
+
return getAvatar(body)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
37
|
+
module.exports.getAvatar = getAvatar
|
package/src/providers/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const providerTiers = {
|
|
4
|
-
email: [['gravatar', 'github'], ['bimi']],
|
|
5
|
-
emailHash: [['gravatar']],
|
|
4
|
+
email: [['gravatar', 'github'], ['libravatar'], ['bimi']],
|
|
5
|
+
emailHash: [['gravatar'], ['libravatar']],
|
|
6
6
|
username: [
|
|
7
7
|
[
|
|
8
8
|
'apple-music',
|
|
@@ -25,6 +25,7 @@ const providerTiers = {
|
|
|
25
25
|
'discord',
|
|
26
26
|
'dockerhub',
|
|
27
27
|
'dribbble',
|
|
28
|
+
'duolingo',
|
|
28
29
|
'facebook',
|
|
29
30
|
'flickr',
|
|
30
31
|
'gitee',
|
|
@@ -127,6 +128,7 @@ module.exports = ctx => {
|
|
|
127
128
|
dockerhub: require('./dockerhub')(ctx),
|
|
128
129
|
dribbble: require('./dribbble')(ctx),
|
|
129
130
|
duckduckgo: require('./duckduckgo')(ctx),
|
|
131
|
+
duolingo: require('./duolingo')(ctx),
|
|
130
132
|
facebook: require('./facebook')(ctx),
|
|
131
133
|
flickr: require('./flickr')(ctx),
|
|
132
134
|
gitee: require('./gitee')(ctx),
|
|
@@ -144,6 +146,7 @@ module.exports = ctx => {
|
|
|
144
146
|
keybase: require('./keybase')(ctx),
|
|
145
147
|
kick: require('./kick')(ctx),
|
|
146
148
|
'ko-fi': require('./ko-fi')(ctx),
|
|
149
|
+
libravatar: require('./libravatar')(ctx),
|
|
147
150
|
linkedin: require('./linkedin')(ctx),
|
|
148
151
|
mastodon: require('./mastodon')(ctx),
|
|
149
152
|
medium: require('./medium')(ctx),
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const stringify = require('../util/stringify')
|
|
4
|
+
const isHash = require('../util/is-hash')
|
|
5
|
+
const { toHash } = require('./gravatar')
|
|
6
|
+
|
|
7
|
+
const CENTRAL_SERVER = 'seccdn.libravatar.org'
|
|
8
|
+
const FEDERATION_SRV_PREFIX = '_avatars-sec._tcp.'
|
|
9
|
+
const HTTPS_PORT = 443
|
|
10
|
+
const MAX_PORT = 65535
|
|
11
|
+
const HOSTNAME_REGEX =
|
|
12
|
+
/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i
|
|
13
|
+
|
|
14
|
+
const parseInput = input => {
|
|
15
|
+
const hash = toHash(input)
|
|
16
|
+
if (isHash(input)) return { hash }
|
|
17
|
+
return { hash, domain: input.trim().toLowerCase().split('@').pop() }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const toServer = ({ name = '', port }) => {
|
|
21
|
+
const hostname = name.replace(/\.$/, '')
|
|
22
|
+
if (!HOSTNAME_REGEX.test(hostname)) return undefined
|
|
23
|
+
if (port === HTTPS_PORT) return hostname
|
|
24
|
+
if (Number.isInteger(port) && port > 0 && port <= MAX_PORT) {
|
|
25
|
+
return `${hostname}:${port}`
|
|
26
|
+
}
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const byPreference = (a, b) => a.priority - b.priority || b.weight - a.weight
|
|
31
|
+
|
|
32
|
+
const getServer = records =>
|
|
33
|
+
records.toSorted(byPreference).map(toServer).find(Boolean)
|
|
34
|
+
|
|
35
|
+
module.exports = ({ constants, dnsResolver }) => {
|
|
36
|
+
const resolveServer = domain =>
|
|
37
|
+
dnsResolver
|
|
38
|
+
.resolveSrv(`${FEDERATION_SRV_PREFIX}${domain}`)
|
|
39
|
+
.then(records => getServer(records) ?? CENTRAL_SERVER)
|
|
40
|
+
.catch(() => CENTRAL_SERVER)
|
|
41
|
+
|
|
42
|
+
return async function libravatar (input) {
|
|
43
|
+
const { hash, domain } = parseInput(input)
|
|
44
|
+
const server = domain ? await resolveServer(domain) : CENTRAL_SERVER
|
|
45
|
+
return `https://${server}/avatar/${hash}?${stringify({
|
|
46
|
+
s: constants.AVATAR_SIZE,
|
|
47
|
+
d: '404',
|
|
48
|
+
gravatarproxy: 'n'
|
|
49
|
+
})}`
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports.parseInput = parseInput
|