@unavatar/core 3.50.0 → 3.52.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
@@ -51,6 +51,7 @@
51
51
  - [Hugging Face](#hugging-face)
52
52
  - [Instagram](#instagram)
53
53
  - [Juejin](#juejin)
54
+ - [Keybase](#keybase)
54
55
  - [Kick](#kick)
55
56
  - [Ko-fi](#ko-fi)
56
57
  - [LinkedIn](#linkedin)
@@ -72,6 +73,7 @@
72
73
  - [Raycast](#raycast)
73
74
  - [Reddit](#reddit)
74
75
  - [Revolut](#revolut)
76
+ - [Roblox](#roblox)
75
77
  - [Snapchat](#snapchat)
76
78
  - [SoundCloud](#soundcloud)
77
79
  - [Spotify](#spotify)
@@ -830,6 +832,12 @@ Get any Juejin user's profile picture by their numeric user ID.
830
832
 
831
833
  e.g., [unavatar.io/juejin/1556564194374926](https://unavatar.io/juejin/1556564194374926)
832
834
 
835
+ ### Keybase
836
+
837
+ Get any Keybase user's profile picture by their username.
838
+
839
+ e.g., [unavatar.io/keybase/chris](https://unavatar.io/keybase/chris)
840
+
833
841
  ### Kick
834
842
 
835
843
  Get any Kick streamer's profile picture by their username.
@@ -974,6 +982,15 @@ Get any Revolut user's profile picture by their Revolut.Me username.
974
982
 
975
983
  e.g., [unavatar.io/revolut/midudev](https://unavatar.io/revolut/midudev)
976
984
 
985
+ ### Roblox
986
+
987
+ Get any Roblox user's avatar headshot by their username or user ID.
988
+
989
+ Available inputs:
990
+
991
+ - Username, e.g., [unavatar.io/roblox/builderman](https://unavatar.io/roblox/builderman)
992
+ - User ID, e.g., [unavatar.io/roblox/id:156](https://unavatar.io/roblox/id:156)
993
+
977
994
  ### Snapchat
978
995
 
979
996
  Get any Snapchat user's profile picture by their 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.50.0",
5
+ "version": "3.52.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -31,6 +31,7 @@ const providerTiers = {
31
31
  'hevy',
32
32
  'instagram',
33
33
  'juejin',
34
+ 'keybase',
34
35
  'kick',
35
36
  'ko-fi',
36
37
  'linkedin',
@@ -51,6 +52,7 @@ const providerTiers = {
51
52
  'raycast',
52
53
  'reddit',
53
54
  'revolut',
55
+ 'roblox',
54
56
  'snapchat',
55
57
  'soundcloud',
56
58
  'spotify',
@@ -122,6 +124,7 @@ module.exports = ctx => {
122
124
  hevy: require('./hevy')(ctx),
123
125
  instagram: require('./instagram')(ctx),
124
126
  juejin: require('./juejin')(ctx),
127
+ keybase: require('./keybase')(ctx),
125
128
  kick: require('./kick')(ctx),
126
129
  'ko-fi': require('./ko-fi')(ctx),
127
130
  linkedin: require('./linkedin')(ctx),
@@ -143,6 +146,7 @@ module.exports = ctx => {
143
146
  raycast: require('./raycast')(ctx),
144
147
  reddit: require('./reddit')(ctx),
145
148
  revolut: require('./revolut')(ctx),
149
+ roblox: require('./roblox')(ctx),
146
150
  snapchat: require('./snapchat')(ctx),
147
151
  soundcloud: require('./soundcloud')(ctx),
148
152
  spotify: require('./spotify')(ctx),
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ const stringify = require('../util/stringify')
4
+
5
+ const API_URL = 'https://keybase.io/_/api/1.0/user/lookup.json'
6
+
7
+ const getAvatarUrl = input =>
8
+ `${API_URL}?${stringify({ username: input, fields: 'pictures' })}`
9
+
10
+ const getAvatar = body => body?.them?.pictures?.primary?.url || undefined
11
+
12
+ module.exports = ({ got }) =>
13
+ async function keybase (input) {
14
+ const { body, statusCode } = await got(getAvatarUrl(input), {
15
+ responseType: 'json',
16
+ throwHttpErrors: false
17
+ })
18
+
19
+ if (statusCode >= 400) return
20
+
21
+ return getAvatar(body)
22
+ }
23
+
24
+ module.exports.getAvatarUrl = getAvatarUrl
25
+ module.exports.getAvatar = getAvatar
@@ -0,0 +1,66 @@
1
+ 'use strict'
2
+
3
+ const stringify = require('../util/stringify')
4
+
5
+ const USERS_API_URL = 'https://users.roblox.com/v1/usernames/users'
6
+ const THUMBNAILS_API_URL =
7
+ 'https://thumbnails.roblox.com/v1/users/avatar-headshot'
8
+ const THUMBNAIL_SIZE = '720x720'
9
+ const THUMBNAIL_COMPLETED_STATE = 'Completed'
10
+ const USER_ID_PREFIX = 'id:'
11
+ const USER_ID_RE = /^\d+$/
12
+
13
+ const parseInput = input =>
14
+ input.startsWith(USER_ID_PREFIX)
15
+ ? { type: 'id', value: input.slice(USER_ID_PREFIX.length) }
16
+ : { type: 'username', value: input }
17
+
18
+ const getAvatarUrl = userId =>
19
+ `${THUMBNAILS_API_URL}?${stringify({
20
+ userIds: userId,
21
+ size: THUMBNAIL_SIZE,
22
+ format: 'Png',
23
+ isCircular: false
24
+ })}`
25
+
26
+ const getAvatar = body => {
27
+ const thumbnail = body?.data?.[0]
28
+ if (thumbnail?.state !== THUMBNAIL_COMPLETED_STATE) return
29
+ const pic = thumbnail.imageUrl
30
+ return typeof pic === 'string' && pic ? pic : undefined
31
+ }
32
+
33
+ const getUserId = async ({ got, username }) => {
34
+ const { body, statusCode } = await got(USERS_API_URL, {
35
+ method: 'POST',
36
+ responseType: 'json',
37
+ throwHttpErrors: false,
38
+ json: { usernames: [username], excludeBannedUsers: true }
39
+ })
40
+
41
+ if (statusCode >= 400) return
42
+
43
+ return body?.data?.[0]?.id
44
+ }
45
+
46
+ module.exports = ({ got }) =>
47
+ async function roblox (input) {
48
+ const { type, value } = parseInput(input)
49
+
50
+ const userId =
51
+ type === 'id' ? value : await getUserId({ got, username: value })
52
+ if (!USER_ID_RE.test(String(userId ?? ''))) return
53
+
54
+ const { body, statusCode } = await got(getAvatarUrl(userId), {
55
+ responseType: 'json',
56
+ throwHttpErrors: false
57
+ })
58
+
59
+ if (statusCode >= 400) return
60
+
61
+ return getAvatar(body)
62
+ }
63
+
64
+ module.exports.parseInput = parseInput
65
+ module.exports.getAvatarUrl = getAvatarUrl
66
+ module.exports.getAvatar = getAvatar