@unavatar/core 3.24.1 → 3.25.1

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
@@ -68,14 +68,13 @@ It's proudly powered by [microlink.io](https://microlink.io/), the headless brow
68
68
 
69
69
  The service is exposed in **unavatar.io** via provider endpoints:
70
70
 
71
- - an **email**: [unavatar.io/email/hello@microlink.io](https://unavatar.io/email/hello@microlink.io)
72
- - a **domain**: [unavatar.io/domain/reddit.com](https://unavatar.io/domain/reddit.com)
71
+ - an **email (auto-detect)**: [unavatar.io/hello@microlink.io](https://unavatar.io/hello@microlink.io) — tries Gravatar, then GitHub
73
72
  - an **email** via Gravatar: [unavatar.io/gravatar/hello@microlink.io](https://unavatar.io/gravatar/hello@microlink.io)
74
73
  - an **email** via GitHub: [unavatar.io/github/sindresorhus@gmail.com](https://unavatar.io/github/sindresorhus@gmail.com)
75
74
  - an **username**: [unavatar.io/github/kikobeats](https://unavatar.io/github/kikobeats)
76
75
  - a **domain**: [unavatar.io/google/reddit.com](https://unavatar.io/google/reddit.com)
77
76
 
78
- Use `/email/:key` and `/domain/:key` for type-based resolution. You can read more in [Email avatars](https://unavatar.io/email) and [providers](https://unavatar.io/docs#providers).
77
+ Use `/:provider/:key` for provider-specific lookups, or pass an email as the only path segment for automatic resolution. You can read more in [Email avatars](https://unavatar.io/email) and [providers](https://unavatar.io/docs#providers).
79
78
 
80
79
  ## Authentication
81
80
 
@@ -652,7 +651,7 @@ Available inputs:
652
651
 
653
652
  ### YouTube
654
653
 
655
- Get any YouTube channel's thumbnail by their handle, username, or channel ID.
654
+ Get any YouTube channel's thumbnail by their handle, legacy username, or channel ID.
656
655
 
657
656
  e.g., [unavatar.io/youtube/casey](https://unavatar.io/youtube/casey)
658
657
 
@@ -746,4 +745,4 @@ Expected errors are known operational cases returned with stable codes.
746
745
 
747
746
  ## Contact
748
747
 
749
- If you have any suggestion or bug to report, please contact to ust mailing to [hello@unavatar.io](mailto:hello@unavatar.io).
748
+ If you have any suggestion or bug to report, please contact to ust mailing to [hello@unavatar.io](mailto:hello@unavatar.io).
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.24.1",
5
+ "version": "3.25.1",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -50,6 +50,10 @@
50
50
  "name": "Nicolas Hedger",
51
51
  "email": "649677+nhedger@users.noreply.github.com"
52
52
  },
53
+ {
54
+ "name": "Mariano Álvarez",
55
+ "email": "66380259+creativoma@users.noreply.github.com"
56
+ },
53
57
  {
54
58
  "name": "Angel M De Miguel",
55
59
  "email": "angel@bitnami.com"
@@ -15,8 +15,10 @@ const ExtendableError = require('../util/error')
15
15
  const DATA_URI_REGEX = dataUriRegex()
16
16
  const DOMAIN_REGEX = urlRegex({ strict: false })
17
17
 
18
+ const isHash = require('../util/is-hash')
19
+
18
20
  const getInputType = input => {
19
- if (isEmail(input)) return 'email'
21
+ if (isEmail(input) || isHash(input)) return 'email'
20
22
  if (stableRegex(DOMAIN_REGEX, input)) return 'domain'
21
23
  return 'username'
22
24
  }
@@ -84,7 +86,12 @@ const factory = ({ constants, providers, providersBy, reachableUrl }) => {
84
86
  }
85
87
 
86
88
  const resolveAutoByType = async (inputType, input, context) => {
87
- const collection = providerEntriesByType[inputType]
89
+ let collection = providerEntriesByType[inputType]
90
+
91
+ if (inputType === 'email' && isHash(input)) {
92
+ collection = collection.filter(([provider]) => provider === 'gravatar')
93
+ }
94
+
88
95
  const promises = new Array(collection.length)
89
96
 
90
97
  for (let index = 0; index < collection.length; index++) {
@@ -3,14 +3,16 @@
3
3
  const crypto = require('crypto')
4
4
 
5
5
  const stringify = require('../util/stringify')
6
+ const isHash = require('../util/is-hash')
6
7
 
7
- const md5 = str => crypto.createHash('md5').update(str).digest('hex')
8
+ const sha256 = str => crypto.createHash('sha256').update(str).digest('hex')
9
+
10
+ const toHash = input =>
11
+ isHash(input) ? input.toLowerCase() : sha256(input.trim().toLowerCase())
8
12
 
9
13
  module.exports = ({ constants }) =>
10
14
  function gravatar (input) {
11
- return `https://gravatar.com/avatar/${md5(
12
- input.trim().toLowerCase()
13
- )}?${stringify({
15
+ return `https://gravatar.com/avatar/${toHash(input)}?${stringify({
14
16
  size: constants.AVATAR_SIZE,
15
17
  d: '404'
16
18
  })}`
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+
3
+ const HASH_REGEX = /^[0-9a-f]{32}$|^[0-9a-f]{64}$/i
4
+
5
+ module.exports = input => HASH_REGEX.test(input)