@unavatar/core 3.7.53 → 3.7.55

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.53",
5
+ "version": "3.7.55",
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
  })
@@ -72,22 +72,26 @@ module.exports = ({ PROXY_TIMEOUT, DEBUG_HTML_TO_FILE, getHTML }) => {
72
72
  const getResult = async ($, statusCode, log, tier) => {
73
73
  const result = getter($)
74
74
  if (typeof result !== 'string' || result === '') {
75
- const { html, ...htmlDebugInfo } = await getHtmlDebugInfo($)
76
- const requestId = typeof res.getHeader === 'function'
77
- ? res.getHeader('x-request-id')
78
- : undefined
79
- const htmlFile = await writeHtmlDebugFile({
80
- debugEnabled: DEBUG_HTML_TO_FILE,
81
- provider: name,
82
- tier,
83
- requestId,
84
- html
85
- }).catch(() => undefined)
75
+ let htmlDebugInfo = {}
76
+
77
+ if (DEBUG_HTML_TO_FILE) {
78
+ const { html, ...info } = await getHtmlDebugInfo($)
79
+ const requestId = typeof res.getHeader === 'function'
80
+ ? res.getHeader('x-request-id')
81
+ : undefined
82
+ const htmlFile = await writeHtmlDebugFile({
83
+ debugEnabled: true,
84
+ provider: name,
85
+ tier,
86
+ requestId,
87
+ html
88
+ }).catch(() => undefined)
89
+ htmlDebugInfo = { ...info, ...(htmlFile ? { htmlFile } : {}) }
90
+ }
86
91
 
87
92
  log.error({
88
93
  statusCode,
89
- ...htmlDebugInfo,
90
- ...(htmlFile ? { htmlFile } : {})
94
+ ...htmlDebugInfo
91
95
  })
92
96
 
93
97
  throw createEmptyProviderValueError({ provider: name, statusCode })