@unavatar/core 3.7.52 → 3.7.54

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
@@ -335,6 +335,15 @@ It resolves user avatar against **youtube.com**.
335
335
 
336
336
  e.g., [unavatar.io/youtube/casey](https://unavatar.io/youtube/casey)
337
337
 
338
+ The endpoint supports specific input formats.
339
+
340
+ If the input starts with `UC` and has 24 characters, it is treated as a channel ID. Otherwise, it is treated as a handle.
341
+
342
+ Available inputs:
343
+
344
+ - `username`: [unavatar.io/youtube/casey](https://unavatar.io/youtube/casey) or [unavatar.io/youtube/@casey](https://unavatar.io/youtube/@casey)
345
+ - `channel`: [unavatar.io/youtube/UC_x5XG1OV2P6uZZ5FSM9Ttw](https://unavatar.io/youtube/UC_x5XG1OV2P6uZZ5FSM9Ttw)
346
+
338
347
  ## Response Format
339
348
 
340
349
  A response is returning the user avatar by default.
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.7.52",
5
+ "version": "3.7.54",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -50,6 +50,10 @@
50
50
  "name": "Angel M De Miguel",
51
51
  "email": "angel@bitnami.com"
52
52
  },
53
+ {
54
+ "name": "Daniel Egbers",
55
+ "email": "daniel@egbers.dev"
56
+ },
53
57
  {
54
58
  "name": "Tom Witkowski",
55
59
  "email": "dev.gummibeer@gmail.com"
@@ -3,6 +3,16 @@
3
3
  module.exports = ({ createHtmlProvider, getOgImage }) =>
4
4
  createHtmlProvider({
5
5
  name: 'youtube',
6
- url: input => `https://www.youtube.com/@${input}`,
6
+ url: input => {
7
+ let path
8
+ if (input.startsWith('@')) {
9
+ path = input
10
+ } else if (input.startsWith('UC') && input.length === 24) {
11
+ path = `channel/${input}`
12
+ } else {
13
+ path = `@${input}`
14
+ }
15
+ return `https://www.youtube.com/${path}`
16
+ },
7
17
  getter: getOgImage
8
18
  })
package/src/util/got.js CHANGED
@@ -7,14 +7,20 @@ const got = require('got')
7
7
 
8
8
  const topUserAgents = require('top-user-agents')
9
9
  const randomUserAgent = uniqueRandomArray(topUserAgents)
10
- const precomputedUaHints = new Map(topUserAgents.map(userAgent => [userAgent, uaHints(userAgent)]))
11
10
 
12
- const getUaHints = userAgent => {
13
- const precomputed = precomputedUaHints.get(userAgent)
14
- if (precomputed !== undefined) return precomputed
11
+ const precomputedUaHints = new Map(
12
+ topUserAgents.map(userAgent => [userAgent, uaHints(userAgent)])
13
+ )
15
14
 
16
- return uaHints(userAgent)
17
- }
15
+ const precomputedUaHintEntries = new Map(
16
+ topUserAgents.map(userAgent => [
17
+ userAgent,
18
+ Object.entries(precomputedUaHints.get(userAgent))
19
+ ])
20
+ )
21
+
22
+ const getUaHintEntries = userAgent =>
23
+ precomputedUaHintEntries.get(userAgent) || Object.entries(uaHints(userAgent))
18
24
 
19
25
  const userAgentHook = options => {
20
26
  let userAgent = options.headers['user-agent']
@@ -23,7 +29,9 @@ const userAgentHook = options => {
23
29
  options.headers['user-agent'] = userAgent
24
30
  }
25
31
 
26
- for (const [key, value] of Object.entries(getUaHints(userAgent))) {
32
+ const uaHintEntries = getUaHintEntries(userAgent)
33
+ for (let index = 0; index < uaHintEntries.length; index++) {
34
+ const [key, value] = uaHintEntries[index]
27
35
  options.headers[key] = value
28
36
  }
29
37
  }