@unavatar/core 3.61.0 → 3.63.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 CHANGED
@@ -51,6 +51,7 @@
51
51
  - [Google](#google)
52
52
  - [Google Play](#google-play)
53
53
  - [Gravatar](#gravatar)
54
+ - [Gumroad](#gumroad)
54
55
  - [Hevy](#hevy)
55
56
  - [Hugging Face](#hugging-face)
56
57
  - [Instagram](#instagram)
@@ -59,6 +60,7 @@
59
60
  - [Keybase](#keybase)
60
61
  - [Kick](#kick)
61
62
  - [Ko-fi](#ko-fi)
63
+ - [Libravatar](#libravatar)
62
64
  - [LinkedIn](#linkedin)
63
65
  - [Mastodon](#mastodon)
64
66
  - [Medium](#medium)
@@ -738,13 +740,13 @@ e.g., [unavatar.io/duckduckgo/microsoft.com](https://unavatar.io/duckduckgo/micr
738
740
 
739
741
  ### Email
740
742
 
741
- 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, GitHub, BIMI in order until one returns an image. No API keys and no SDK are required.
743
+ 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.
742
744
 
743
745
  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.
744
746
 
745
747
  Automatic resolution
746
748
 
747
- 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, GitHub, BIMI).
749
+ 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).
748
750
 
749
751
  - Typed route `unavatar.io/email/{email}`: [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
750
752
  - Bare path `unavatar.io/{email}`: [unavatar.io/hello@microlink.io](https://unavatar.io/hello@microlink.io)
@@ -755,6 +757,7 @@ Target a specific provider when you know where the avatar comes from.
755
757
 
756
758
  - 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)
757
759
  - GitHub (`unavatar.io/github/{email}`) — public profile email or commit history: [unavatar.io/github/sindresorhus@gmail.com](https://unavatar.io/github/sindresorhus@gmail.com)
760
+ - 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)
758
761
  - 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)
759
762
 
760
763
  e.g., [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
@@ -837,7 +840,13 @@ Available inputs:
837
840
 
838
841
  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.
839
842
 
840
- 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 supports both hash formats.
843
+ 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.
844
+
845
+ ### Gumroad
846
+
847
+ Get any Gumroad creator's profile picture by their username (the subdomain of their store).
848
+
849
+ e.g., [unavatar.io/gumroad/sahil](https://unavatar.io/gumroad/sahil)
841
850
 
842
851
  ### Hevy
843
852
 
@@ -890,6 +899,20 @@ Get any Ko-fi page's profile picture by the creator username.
890
899
 
891
900
  e.g., [unavatar.io/ko-fi/geekshock](https://unavatar.io/ko-fi/geekshock)
892
901
 
902
+ ### Libravatar
903
+
904
+ 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).
905
+
906
+ Available inputs:
907
+
908
+ - Email address, e.g., [unavatar.io/libravatar/francois@fmarier.org](https://unavatar.io/libravatar/francois@fmarier.org)
909
+ - SHA-256 hash, e.g., [unavatar.io/libravatar/857915e8681217376523fa2c4653a499a7dc6826197b077d35fc029d7c38bda1](https://unavatar.io/libravatar/857915e8681217376523fa2c4653a499a7dc6826197b077d35fc029d7c38bda1)
910
+ - MD5 hash, e.g., [unavatar.io/libravatar/7cc352a2907216992f0f16d2af50b070](https://unavatar.io/libravatar/7cc352a2907216992f0f16d2af50b070)
911
+
912
+ 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.
913
+
914
+ In the email chain, Libravatar runs only after Gravatar and GitHub miss, so it never overrides or slows down a Gravatar hit.
915
+
893
916
  ### LinkedIn
894
917
 
895
918
  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.61.0",
5
+ "version": "3.63.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -17,3 +17,5 @@ module.exports = ({ constants }) =>
17
17
  d: '404'
18
18
  })}`
19
19
  }
20
+
21
+ module.exports.toHash = toHash
@@ -0,0 +1,45 @@
1
+ 'use strict'
2
+
3
+ const { get } = require('lodash')
4
+
5
+ const SUBDOMAIN_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i
6
+ const DEFAULT_AVATAR_MARKER = 'gumroad-default-avatar'
7
+
8
+ const parseInput = input =>
9
+ typeof input === 'string' && SUBDOMAIN_REGEX.test(input)
10
+ ? input.toLowerCase()
11
+ : undefined
12
+
13
+ const getAvatarUrl = input => `https://${input}.gumroad.com/`
14
+
15
+ const getAvatar = ({ $, NOT_FOUND }) => {
16
+ const page = $('#app').attr('data-page')
17
+ if (!page) return
18
+ const avatarUrl = get(JSON.parse(page), [
19
+ 'props',
20
+ 'creator_profile',
21
+ 'avatar_url'
22
+ ])
23
+ if (!avatarUrl || avatarUrl.includes(DEFAULT_AVATAR_MARKER)) return NOT_FOUND
24
+ return avatarUrl
25
+ }
26
+
27
+ module.exports = ({ createHtmlProvider, NOT_FOUND }) => {
28
+ const htmlProvider = createHtmlProvider({
29
+ name: 'gumroad',
30
+ url: getAvatarUrl,
31
+ getter: $ => getAvatar({ $, NOT_FOUND })
32
+ })
33
+
34
+ const provider = (input, context) => {
35
+ const username = parseInput(input)
36
+ return username ? htmlProvider(username, context) : undefined
37
+ }
38
+
39
+ provider.getUrl = getAvatarUrl
40
+ return provider
41
+ }
42
+
43
+ module.exports.parseInput = parseInput
44
+ module.exports.getAvatarUrl = getAvatarUrl
45
+ module.exports.getAvatar = getAvatar
@@ -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',
@@ -31,6 +31,7 @@ const providerTiers = {
31
31
  'github',
32
32
  'gitlab',
33
33
  'google-play',
34
+ 'gumroad',
34
35
  'huggingface',
35
36
  'hevy',
36
37
  'instagram',
@@ -134,6 +135,7 @@ module.exports = ctx => {
134
135
  google: require('./google')(ctx),
135
136
  'google-play': require('./google-play')(ctx),
136
137
  gravatar: require('./gravatar')(ctx),
138
+ gumroad: require('./gumroad')(ctx),
137
139
  huggingface: require('./huggingface')(ctx),
138
140
  hevy: require('./hevy')(ctx),
139
141
  instagram: require('./instagram')(ctx),
@@ -142,6 +144,7 @@ module.exports = ctx => {
142
144
  keybase: require('./keybase')(ctx),
143
145
  kick: require('./kick')(ctx),
144
146
  'ko-fi': require('./ko-fi')(ctx),
147
+ libravatar: require('./libravatar')(ctx),
145
148
  linkedin: require('./linkedin')(ctx),
146
149
  mastodon: require('./mastodon')(ctx),
147
150
  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