@unavatar/core 3.50.0 → 3.51.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 +10 -0
- package/package.json +1 -1
- package/src/providers/index.js +2 -0
- package/src/providers/roblox.js +66 -0
package/README.md
CHANGED
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
- [Raycast](#raycast)
|
|
73
73
|
- [Reddit](#reddit)
|
|
74
74
|
- [Revolut](#revolut)
|
|
75
|
+
- [Roblox](#roblox)
|
|
75
76
|
- [Snapchat](#snapchat)
|
|
76
77
|
- [SoundCloud](#soundcloud)
|
|
77
78
|
- [Spotify](#spotify)
|
|
@@ -974,6 +975,15 @@ Get any Revolut user's profile picture by their Revolut.Me username.
|
|
|
974
975
|
|
|
975
976
|
e.g., [unavatar.io/revolut/midudev](https://unavatar.io/revolut/midudev)
|
|
976
977
|
|
|
978
|
+
### Roblox
|
|
979
|
+
|
|
980
|
+
Get any Roblox user's avatar headshot by their username or user ID.
|
|
981
|
+
|
|
982
|
+
Available inputs:
|
|
983
|
+
|
|
984
|
+
- Username, e.g., [unavatar.io/roblox/builderman](https://unavatar.io/roblox/builderman)
|
|
985
|
+
- User ID, e.g., [unavatar.io/roblox/id:156](https://unavatar.io/roblox/id:156)
|
|
986
|
+
|
|
977
987
|
### Snapchat
|
|
978
988
|
|
|
979
989
|
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.
|
|
5
|
+
"version": "3.51.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
package/src/providers/index.js
CHANGED
|
@@ -51,6 +51,7 @@ const providerTiers = {
|
|
|
51
51
|
'raycast',
|
|
52
52
|
'reddit',
|
|
53
53
|
'revolut',
|
|
54
|
+
'roblox',
|
|
54
55
|
'snapchat',
|
|
55
56
|
'soundcloud',
|
|
56
57
|
'spotify',
|
|
@@ -143,6 +144,7 @@ module.exports = ctx => {
|
|
|
143
144
|
raycast: require('./raycast')(ctx),
|
|
144
145
|
reddit: require('./reddit')(ctx),
|
|
145
146
|
revolut: require('./revolut')(ctx),
|
|
147
|
+
roblox: require('./roblox')(ctx),
|
|
146
148
|
snapchat: require('./snapchat')(ctx),
|
|
147
149
|
soundcloud: require('./soundcloud')(ctx),
|
|
148
150
|
spotify: require('./spotify')(ctx),
|
|
@@ -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
|