@unavatar/core 3.57.0 → 3.59.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
@@ -34,6 +34,7 @@
34
34
  - [Cursor](#cursor)
35
35
  - [Dailymotion](#dailymotion)
36
36
  - [Deezer](#deezer)
37
+ - [DEV](#dev)
37
38
  - [DeviantArt](#deviantart)
38
39
  - [Discord](#discord)
39
40
  - [Docker Hub](#docker-hub)
@@ -53,6 +54,7 @@
53
54
  - [Hugging Face](#hugging-face)
54
55
  - [Instagram](#instagram)
55
56
  - [Juejin](#juejin)
57
+ - [Kaggle](#kaggle)
56
58
  - [Keybase](#keybase)
57
59
  - [Kick](#kick)
58
60
  - [Ko-fi](#ko-fi)
@@ -65,6 +67,7 @@
65
67
  - [NetEase Music](#netease-music)
66
68
  - [npm](#npm)
67
69
  - [OnlyFans](#onlyfans)
70
+ - [Open Collective](#open-collective)
68
71
  - [OpenStreetMap](#openstreetmap)
69
72
  - [osu!](#osu)
70
73
  - [Patreon](#patreon)
@@ -680,6 +683,12 @@ Available inputs:
680
683
  - `playlist`: [unavatar.io/deezer/playlist:908622995](https://unavatar.io/deezer/playlist:908622995)
681
684
  - `track`: [unavatar.io/deezer/track:3135556](https://unavatar.io/deezer/track:3135556)
682
685
 
686
+ ### DEV
687
+
688
+ Get any [DEV](https://dev.to) user's profile picture by username, or an organization's logo by its slug.
689
+
690
+ e.g., [unavatar.io/devto/ben](https://unavatar.io/devto/ben)
691
+
683
692
  ### DeviantArt
684
693
 
685
694
  Get any DeviantArt user's profile picture by their username.
@@ -849,6 +858,12 @@ Get any Juejin user's profile picture by their numeric user ID.
849
858
 
850
859
  e.g., [unavatar.io/juejin/1556564194374926](https://unavatar.io/juejin/1556564194374926)
851
860
 
861
+ ### Kaggle
862
+
863
+ Get any Kaggle user's profile picture by their username.
864
+
865
+ e.g., [unavatar.io/kaggle/jhoward](https://unavatar.io/kaggle/jhoward)
866
+
852
867
  ### Keybase
853
868
 
854
869
  Get any Keybase user's profile picture by their username.
@@ -929,6 +944,12 @@ Get any OnlyFans creator's profile picture by their username.
929
944
 
930
945
  e.g., [unavatar.io/onlyfans/amandaribas](https://unavatar.io/onlyfans/amandaribas)
931
946
 
947
+ ### Open Collective
948
+
949
+ Get any Open Collective account's avatar by its profile slug, for collectives, organizations, and individuals.
950
+
951
+ e.g., [unavatar.io/opencollective/webpack](https://unavatar.io/opencollective/webpack)
952
+
932
953
  ### OpenStreetMap
933
954
 
934
955
  Get any OpenStreetMap contributor's profile picture. Accepts either a numeric user ID or a username.
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.57.0",
5
+ "version": "3.59.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://dev.to/api'
4
+
5
+ const PLACEHOLDER_URL =
6
+ 'https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png'
7
+
8
+ const RESIZED_IMAGE_RE = /^(.+\/dynamic\/image\/)([^/]+)\/(https?%3A%2F%2F.+)$/i
9
+
10
+ const DIMENSION_RE = /\b(width|height)=\d+/g
11
+
12
+ const parseInput = input => input.trim().replace(/^@/, '').toLowerCase()
13
+
14
+ const getUserAvatarUrl = input =>
15
+ `${API_URL}/users/by_username?url=${encodeURIComponent(input)}`
16
+
17
+ const getOrganizationAvatarUrl = input =>
18
+ `${API_URL}/organizations/${encodeURIComponent(input)}`
19
+
20
+ const getAvatar = ({ body, size }) => {
21
+ const image = body?.profile_image
22
+ if (typeof image !== 'string' || !image) return
23
+
24
+ const match = RESIZED_IMAGE_RE.exec(image)
25
+ const originalUrl = match ? decodeURIComponent(match[3]) : image
26
+ if (originalUrl === PLACEHOLDER_URL) return
27
+ if (!match) return image
28
+
29
+ const [, prefix, options, encodedOriginalUrl] = match
30
+ const resizedOptions = options.replace(DIMENSION_RE, `$1=${size}`)
31
+ return `${prefix}${resizedOptions}/${encodedOriginalUrl}`
32
+ }
33
+
34
+ const fetchAvatarUrl = async ({ got, url, size }) => {
35
+ const { statusCode, body } = await got(url, {
36
+ responseType: 'json',
37
+ throwHttpErrors: false
38
+ })
39
+
40
+ if (statusCode >= 400) return
41
+
42
+ return getAvatar({ body, size })
43
+ }
44
+
45
+ module.exports = ({ constants, got }) =>
46
+ async function devto (input) {
47
+ const username = parseInput(input)
48
+ const size = constants.AVATAR_SIZE
49
+
50
+ const userAvatarUrl = await fetchAvatarUrl({
51
+ got,
52
+ size,
53
+ url: getUserAvatarUrl(username)
54
+ })
55
+ if (userAvatarUrl) return userAvatarUrl
56
+
57
+ return fetchAvatarUrl({
58
+ got,
59
+ size,
60
+ url: getOrganizationAvatarUrl(username)
61
+ })
62
+ }
63
+
64
+ module.exports.parseInput = parseInput
65
+ module.exports.getUserAvatarUrl = getUserAvatarUrl
66
+ module.exports.getOrganizationAvatarUrl = getOrganizationAvatarUrl
67
+ module.exports.getAvatar = getAvatar
@@ -20,6 +20,7 @@ const providerTiers = {
20
20
  'dailymotion',
21
21
  'deezer',
22
22
  'deviantart',
23
+ 'devto',
23
24
  'discord',
24
25
  'dockerhub',
25
26
  'dribbble',
@@ -33,6 +34,7 @@ const providerTiers = {
33
34
  'hevy',
34
35
  'instagram',
35
36
  'juejin',
37
+ 'kaggle',
36
38
  'keybase',
37
39
  'kick',
38
40
  'ko-fi',
@@ -44,6 +46,7 @@ const providerTiers = {
44
46
  'netease-music',
45
47
  'npm',
46
48
  'onlyfans',
49
+ 'opencollective',
47
50
  'openstreetmap',
48
51
  'osu',
49
52
  'patreon',
@@ -115,6 +118,7 @@ module.exports = ctx => {
115
118
  dailymotion: require('./dailymotion')(ctx),
116
119
  deezer: require('./deezer')(ctx),
117
120
  deviantart: require('./deviantart')(ctx),
121
+ devto: require('./devto')(ctx),
118
122
  discord: require('./discord')(ctx),
119
123
  dockerhub: require('./dockerhub')(ctx),
120
124
  dribbble: require('./dribbble')(ctx),
@@ -131,6 +135,7 @@ module.exports = ctx => {
131
135
  hevy: require('./hevy')(ctx),
132
136
  instagram: require('./instagram')(ctx),
133
137
  juejin: require('./juejin')(ctx),
138
+ kaggle: require('./kaggle')(ctx),
134
139
  keybase: require('./keybase')(ctx),
135
140
  kick: require('./kick')(ctx),
136
141
  'ko-fi': require('./ko-fi')(ctx),
@@ -143,6 +148,7 @@ module.exports = ctx => {
143
148
  'netease-music': require('./netease-music')(ctx),
144
149
  npm: require('./npm')(ctx),
145
150
  onlyfans: require('./onlyfans')(ctx),
151
+ opencollective: require('./opencollective')(ctx),
146
152
  openstreetmap: require('./openstreetmap')(ctx),
147
153
  osu: require('./osu')(ctx),
148
154
  patreon: require('./patreon')(ctx),
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const THUMBNAIL_URL_PREFIX =
4
+ 'https://storage.googleapis.com/kaggle-avatars/thumbnails/'
5
+ const FULL_SIZE_URL_PREFIX =
6
+ 'https://storage.googleapis.com/kaggle-avatars/images/'
7
+ const DEFAULT_AVATAR_FILENAME = 'default-thumb.png'
8
+ const UNCHALLENGED_CRAWLER_USER_AGENT =
9
+ 'Googlebot/2.1 (+http://www.google.com/bot.html)'
10
+
11
+ const getAvatarUrl = input => `https://www.kaggle.com/${input}`
12
+
13
+ const getAvatar = ({ $, NOT_FOUND }) => {
14
+ const src =
15
+ $('meta[name="twitter:image"]').attr('content') ||
16
+ $('meta[property="twitter:image"]').attr('content')
17
+ if (!src) return
18
+
19
+ if (!src.startsWith(THUMBNAIL_URL_PREFIX)) return NOT_FOUND
20
+
21
+ const filename = src.slice(THUMBNAIL_URL_PREFIX.length)
22
+ if (filename === DEFAULT_AVATAR_FILENAME) return NOT_FOUND
23
+
24
+ return FULL_SIZE_URL_PREFIX + filename
25
+ }
26
+
27
+ module.exports = ({ createHtmlProvider, NOT_FOUND }) =>
28
+ createHtmlProvider({
29
+ name: 'kaggle',
30
+ url: getAvatarUrl,
31
+ getter: $ => getAvatar({ $, NOT_FOUND }),
32
+ htmlOpts: () => ({
33
+ headers: { 'user-agent': UNCHALLENGED_CRAWLER_USER_AGENT }
34
+ })
35
+ })
36
+
37
+ module.exports.getAvatarUrl = getAvatarUrl
38
+ module.exports.getAvatar = getAvatar
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ const PROFILE_URL = 'https://opencollective.com'
4
+ const IMAGES_URL = 'https://images.opencollective.com'
5
+
6
+ const getProfileUrl = input =>
7
+ `${PROFILE_URL}/${encodeURIComponent(input)}.json`
8
+
9
+ const getAvatarUrl = ({ constants, slug }) =>
10
+ `${IMAGES_URL}/${encodeURIComponent(slug)}/avatar/${
11
+ constants.AVATAR_SIZE
12
+ }.png`
13
+
14
+ module.exports = ({ constants, got }) =>
15
+ async function opencollective (input) {
16
+ const { body, statusCode } = await got(getProfileUrl(input), {
17
+ responseType: 'json',
18
+ throwHttpErrors: false
19
+ })
20
+
21
+ if (statusCode >= 400 || !body?.image || !body.slug) return
22
+
23
+ return getAvatarUrl({ constants, slug: body.slug })
24
+ }
25
+
26
+ module.exports.getProfileUrl = getProfileUrl
27
+ module.exports.getAvatarUrl = getAvatarUrl