@unavatar/core 3.19.7 → 3.20.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/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.19.7",
5
+ "version": "3.20.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -139,7 +139,7 @@
139
139
  "ms": "~2.1.3",
140
140
  "p-any": "~3.0.0",
141
141
  "p-timeout": "~4.1.0",
142
- "puppeteer": "~24.41.0",
142
+ "puppeteer": "~24.42.0",
143
143
  "re2": "~1.24.0",
144
144
  "srcset": "~4.0.0",
145
145
  "stable-regex": "~1.0.1",
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+ const BUDDY_ICON_URL_PATTERN = /(?:https?:)?\/\/[^"'()\s]*\/buddyicons\/[^"'()\s]+/i
4
+ const CSS_URL_PATTERN = /url\((['"]?)([^)'"]+)\1\)/i
5
+ const unescapePathSlashes = value => value?.replace(/\\\//g, '/')
6
+
7
+ const getBuddyIconFromText = value => {
8
+ const normalizedValue = unescapePathSlashes(value)
9
+ if (typeof normalizedValue !== 'string') return
10
+ return normalizedValue.match(BUDDY_ICON_URL_PATTERN)?.[0]
11
+ }
12
+
13
+ const getAvatarUrl = input => {
14
+ const [first, second] = input.split(':')
15
+ const type = second ? first : 'user'
16
+ const id = second ?? first
17
+
18
+ switch (type) {
19
+ case 'user':
20
+ case 'photos':
21
+ return `https://www.flickr.com/photos/${id}/`
22
+ case 'group':
23
+ case 'groups':
24
+ return `https://www.flickr.com/groups/${id}/`
25
+ default:
26
+ throw new Error(`Unsupported Flickr type: ${type}`)
27
+ }
28
+ }
29
+
30
+ const getBuddyIconFromCss = value => {
31
+ const cssUrl = value?.match(CSS_URL_PATTERN)?.[2]
32
+ return getBuddyIconFromText(cssUrl)
33
+ }
34
+
35
+ const getAvatarFromMarkup = $ => {
36
+ const imgBuddyIcon = $('img[src*="/buddyicons/"]').first().attr('src')
37
+ if (imgBuddyIcon) return imgBuddyIcon
38
+
39
+ const buddyIconFromStyle = getBuddyIconFromCss(
40
+ $('[style*="buddyicons/"]').first().attr('style')
41
+ )
42
+ if (buddyIconFromStyle) return buddyIconFromStyle
43
+
44
+ return getBuddyIconFromText($.html())
45
+ }
46
+
47
+ module.exports = ({ createHtmlProvider }) =>
48
+ createHtmlProvider({
49
+ name: 'flickr',
50
+ url: getAvatarUrl,
51
+ getter: getAvatarFromMarkup
52
+ })
53
+
54
+ module.exports.getAvatarUrl = getAvatarUrl
55
+ module.exports.getAvatarFromMarkup = getAvatarFromMarkup
@@ -10,6 +10,7 @@ const providersBy = {
10
10
  'discord',
11
11
  'dribbble',
12
12
  'facebook',
13
+ 'flickr',
13
14
  'github',
14
15
  'gitlab',
15
16
  'instagram',
@@ -52,6 +53,7 @@ module.exports = ctx => {
52
53
  dribbble: require('./dribbble')(ctx),
53
54
  duckduckgo: require('./duckduckgo')(ctx),
54
55
  facebook: require('./facebook')(ctx),
56
+ flickr: require('./flickr')(ctx),
55
57
  github: require('./github')(ctx),
56
58
  gitlab: require('./gitlab')(ctx),
57
59
  google: require('./google')(ctx),