@unavatar/core 3.58.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
@@ -54,6 +54,7 @@
54
54
  - [Hugging Face](#hugging-face)
55
55
  - [Instagram](#instagram)
56
56
  - [Juejin](#juejin)
57
+ - [Kaggle](#kaggle)
57
58
  - [Keybase](#keybase)
58
59
  - [Kick](#kick)
59
60
  - [Ko-fi](#ko-fi)
@@ -66,6 +67,7 @@
66
67
  - [NetEase Music](#netease-music)
67
68
  - [npm](#npm)
68
69
  - [OnlyFans](#onlyfans)
70
+ - [Open Collective](#open-collective)
69
71
  - [OpenStreetMap](#openstreetmap)
70
72
  - [osu!](#osu)
71
73
  - [Patreon](#patreon)
@@ -856,6 +858,12 @@ Get any Juejin user's profile picture by their numeric user ID.
856
858
 
857
859
  e.g., [unavatar.io/juejin/1556564194374926](https://unavatar.io/juejin/1556564194374926)
858
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
+
859
867
  ### Keybase
860
868
 
861
869
  Get any Keybase user's profile picture by their username.
@@ -936,6 +944,12 @@ Get any OnlyFans creator's profile picture by their username.
936
944
 
937
945
  e.g., [unavatar.io/onlyfans/amandaribas](https://unavatar.io/onlyfans/amandaribas)
938
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
+
939
953
  ### OpenStreetMap
940
954
 
941
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.58.0",
5
+ "version": "3.59.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -34,6 +34,7 @@ const providerTiers = {
34
34
  'hevy',
35
35
  'instagram',
36
36
  'juejin',
37
+ 'kaggle',
37
38
  'keybase',
38
39
  'kick',
39
40
  'ko-fi',
@@ -45,6 +46,7 @@ const providerTiers = {
45
46
  'netease-music',
46
47
  'npm',
47
48
  'onlyfans',
49
+ 'opencollective',
48
50
  'openstreetmap',
49
51
  'osu',
50
52
  'patreon',
@@ -133,6 +135,7 @@ module.exports = ctx => {
133
135
  hevy: require('./hevy')(ctx),
134
136
  instagram: require('./instagram')(ctx),
135
137
  juejin: require('./juejin')(ctx),
138
+ kaggle: require('./kaggle')(ctx),
136
139
  keybase: require('./keybase')(ctx),
137
140
  kick: require('./kick')(ctx),
138
141
  'ko-fi': require('./ko-fi')(ctx),
@@ -145,6 +148,7 @@ module.exports = ctx => {
145
148
  'netease-music': require('./netease-music')(ctx),
146
149
  npm: require('./npm')(ctx),
147
150
  onlyfans: require('./onlyfans')(ctx),
151
+ opencollective: require('./opencollective')(ctx),
148
152
  openstreetmap: require('./openstreetmap')(ctx),
149
153
  osu: require('./osu')(ctx),
150
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