@unavatar/core 3.62.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
@@ -60,6 +60,7 @@
60
60
  - [Keybase](#keybase)
61
61
  - [Kick](#kick)
62
62
  - [Ko-fi](#ko-fi)
63
+ - [Libravatar](#libravatar)
63
64
  - [LinkedIn](#linkedin)
64
65
  - [Mastodon](#mastodon)
65
66
  - [Medium](#medium)
@@ -739,13 +740,13 @@ e.g., [unavatar.io/duckduckgo/microsoft.com](https://unavatar.io/duckduckgo/micr
739
740
 
740
741
  ### Email
741
742
 
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, 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.
743
744
 
744
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.
745
746
 
746
747
  Automatic resolution
747
748
 
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, 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).
749
750
 
750
751
  - Typed route `unavatar.io/email/{email}`: [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
751
752
  - Bare path `unavatar.io/{email}`: [unavatar.io/hello@microlink.io](https://unavatar.io/hello@microlink.io)
@@ -756,6 +757,7 @@ Target a specific provider when you know where the avatar comes from.
756
757
 
757
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)
758
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)
759
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)
760
762
 
761
763
  e.g., [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
@@ -838,7 +840,7 @@ Available inputs:
838
840
 
839
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.
840
842
 
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 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.
842
844
 
843
845
  ### Gumroad
844
846
 
@@ -897,6 +899,20 @@ Get any Ko-fi page's profile picture by the creator username.
897
899
 
898
900
  e.g., [unavatar.io/ko-fi/geekshock](https://unavatar.io/ko-fi/geekshock)
899
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
+
900
916
  ### LinkedIn
901
917
 
902
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.62.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
@@ -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',
@@ -144,6 +144,7 @@ module.exports = ctx => {
144
144
  keybase: require('./keybase')(ctx),
145
145
  kick: require('./kick')(ctx),
146
146
  'ko-fi': require('./ko-fi')(ctx),
147
+ libravatar: require('./libravatar')(ctx),
147
148
  linkedin: require('./linkedin')(ctx),
148
149
  mastodon: require('./mastodon')(ctx),
149
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