@unavatar/core 3.49.9 → 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 +17 -0
- package/package.json +1 -1
- package/src/providers/codeforces.js +33 -0
- package/src/providers/index.js +4 -0
- package/src/providers/roblox.js +66 -0
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
- [Bluesky](#bluesky)
|
|
28
28
|
- [Buy Me a Coffee](#buy-me-a-coffee)
|
|
29
29
|
- [Cash App](#cash-app)
|
|
30
|
+
- [Codeforces](#codeforces)
|
|
30
31
|
- [CodePen](#codepen)
|
|
31
32
|
- [Cults3D](#cults3d)
|
|
32
33
|
- [Cursor](#cursor)
|
|
@@ -71,6 +72,7 @@
|
|
|
71
72
|
- [Raycast](#raycast)
|
|
72
73
|
- [Reddit](#reddit)
|
|
73
74
|
- [Revolut](#revolut)
|
|
75
|
+
- [Roblox](#roblox)
|
|
74
76
|
- [Snapchat](#snapchat)
|
|
75
77
|
- [SoundCloud](#soundcloud)
|
|
76
78
|
- [Spotify](#spotify)
|
|
@@ -621,6 +623,12 @@ Get any Cash App user's profile picture by their Cashtag.
|
|
|
621
623
|
|
|
622
624
|
e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
|
|
623
625
|
|
|
626
|
+
### Codeforces
|
|
627
|
+
|
|
628
|
+
Get any Codeforces user's profile picture by their handle.
|
|
629
|
+
|
|
630
|
+
e.g., [unavatar.io/codeforces/tourist](https://unavatar.io/codeforces/tourist)
|
|
631
|
+
|
|
624
632
|
### CodePen
|
|
625
633
|
|
|
626
634
|
Get any CodePen user's profile picture by their username.
|
|
@@ -967,6 +975,15 @@ Get any Revolut user's profile picture by their Revolut.Me username.
|
|
|
967
975
|
|
|
968
976
|
e.g., [unavatar.io/revolut/midudev](https://unavatar.io/revolut/midudev)
|
|
969
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
|
+
|
|
970
987
|
### Snapchat
|
|
971
988
|
|
|
972
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",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'https://codeforces.com/api/user.info'
|
|
4
|
+
|
|
5
|
+
const HANDLES_SEPARATOR = ';'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_PHOTO_RE = /\/no-(title|avatar)\.jpg$/
|
|
8
|
+
|
|
9
|
+
const getAvatarUrl = input => `${API_URL}?handles=${encodeURIComponent(input)}`
|
|
10
|
+
|
|
11
|
+
const getAvatar = body => {
|
|
12
|
+
const pic = body?.result?.[0]?.titlePhoto
|
|
13
|
+
if (typeof pic !== 'string' || !pic) return undefined
|
|
14
|
+
if (DEFAULT_PHOTO_RE.test(pic)) return undefined
|
|
15
|
+
return pic
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = ({ got }) =>
|
|
19
|
+
async function codeforces (input) {
|
|
20
|
+
if (input.includes(HANDLES_SEPARATOR)) return
|
|
21
|
+
|
|
22
|
+
const { body, statusCode } = await got(getAvatarUrl(input), {
|
|
23
|
+
responseType: 'json',
|
|
24
|
+
throwHttpErrors: false
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
if (statusCode >= 400) return
|
|
28
|
+
|
|
29
|
+
return getAvatar(body)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
33
|
+
module.exports.getAvatar = getAvatar
|
package/src/providers/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const providerTiers = {
|
|
|
12
12
|
'bluesky',
|
|
13
13
|
'buymeacoffee',
|
|
14
14
|
'cashapp',
|
|
15
|
+
'codeforces',
|
|
15
16
|
'codepen',
|
|
16
17
|
'cults3d',
|
|
17
18
|
'cursor',
|
|
@@ -50,6 +51,7 @@ const providerTiers = {
|
|
|
50
51
|
'raycast',
|
|
51
52
|
'reddit',
|
|
52
53
|
'revolut',
|
|
54
|
+
'roblox',
|
|
53
55
|
'snapchat',
|
|
54
56
|
'soundcloud',
|
|
55
57
|
'spotify',
|
|
@@ -99,6 +101,7 @@ module.exports = ctx => {
|
|
|
99
101
|
bluesky: require('./bluesky')(ctx),
|
|
100
102
|
buymeacoffee: require('./buymeacoffee')(ctx),
|
|
101
103
|
cashapp: require('./cashapp')(ctx),
|
|
104
|
+
codeforces: require('./codeforces')(ctx),
|
|
102
105
|
codepen: require('./codepen')(ctx),
|
|
103
106
|
cults3d: require('./cults3d')(ctx),
|
|
104
107
|
cursor: require('./cursor')(ctx),
|
|
@@ -141,6 +144,7 @@ module.exports = ctx => {
|
|
|
141
144
|
raycast: require('./raycast')(ctx),
|
|
142
145
|
reddit: require('./reddit')(ctx),
|
|
143
146
|
revolut: require('./revolut')(ctx),
|
|
147
|
+
roblox: require('./roblox')(ctx),
|
|
144
148
|
snapchat: require('./snapchat')(ctx),
|
|
145
149
|
soundcloud: require('./soundcloud')(ctx),
|
|
146
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
|