@unavatar/core 3.60.0 → 3.61.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 +7 -0
- package/package.json +1 -1
- package/src/providers/index.js +2 -0
- package/src/providers/sketchfab.js +39 -0
package/README.md
CHANGED
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
- [Reddit](#reddit)
|
|
84
84
|
- [Revolut](#revolut)
|
|
85
85
|
- [Roblox](#roblox)
|
|
86
|
+
- [Sketchfab](#sketchfab)
|
|
86
87
|
- [Snapchat](#snapchat)
|
|
87
88
|
- [SoundCloud](#soundcloud)
|
|
88
89
|
- [Spotify](#spotify)
|
|
@@ -1060,6 +1061,12 @@ Available inputs:
|
|
|
1060
1061
|
- Username, e.g., [unavatar.io/roblox/builderman](https://unavatar.io/roblox/builderman)
|
|
1061
1062
|
- User ID, e.g., [unavatar.io/roblox/id:156](https://unavatar.io/roblox/id:156)
|
|
1062
1063
|
|
|
1064
|
+
### Sketchfab
|
|
1065
|
+
|
|
1066
|
+
Get any Sketchfab creator's profile picture by their username.
|
|
1067
|
+
|
|
1068
|
+
e.g., [unavatar.io/sketchfab/nasa](https://unavatar.io/sketchfab/nasa)
|
|
1069
|
+
|
|
1063
1070
|
### Snapchat
|
|
1064
1071
|
|
|
1065
1072
|
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.61.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
package/src/providers/index.js
CHANGED
|
@@ -62,6 +62,7 @@ const providerTiers = {
|
|
|
62
62
|
'reddit',
|
|
63
63
|
'revolut',
|
|
64
64
|
'roblox',
|
|
65
|
+
'sketchfab',
|
|
65
66
|
'snapchat',
|
|
66
67
|
'soundcloud',
|
|
67
68
|
'spotify',
|
|
@@ -165,6 +166,7 @@ module.exports = ctx => {
|
|
|
165
166
|
reddit: require('./reddit')(ctx),
|
|
166
167
|
revolut: require('./revolut')(ctx),
|
|
167
168
|
roblox: require('./roblox')(ctx),
|
|
169
|
+
sketchfab: require('./sketchfab')(ctx),
|
|
168
170
|
snapchat: require('./snapchat')(ctx),
|
|
169
171
|
soundcloud: require('./soundcloud')(ctx),
|
|
170
172
|
spotify: require('./spotify')(ctx),
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'https://api.sketchfab.com/v3/users'
|
|
4
|
+
|
|
5
|
+
const DEFAULT_AVATAR_UIDS = new Set([
|
|
6
|
+
'3ef1bd11d3eb4b57a0b353e8f2e5fc3e',
|
|
7
|
+
'51af6a870cce449eb75b0345feebaebb',
|
|
8
|
+
'78fa317e46024a5283765aa34df5e508'
|
|
9
|
+
])
|
|
10
|
+
|
|
11
|
+
const getAvatarUrl = input =>
|
|
12
|
+
`${API_URL}/@${encodeURIComponent(input.replace(/^@/, ''))}`
|
|
13
|
+
|
|
14
|
+
const getAvatar = body => {
|
|
15
|
+
const avatar = body?.avatar
|
|
16
|
+
if (!avatar || DEFAULT_AVATAR_UIDS.has(avatar.uid)) return
|
|
17
|
+
|
|
18
|
+
const largest = (avatar.images ?? []).reduce(
|
|
19
|
+
(best, image) => (image.width > (best?.width ?? 0) ? image : best),
|
|
20
|
+
undefined
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
return largest?.url || undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = ({ got }) =>
|
|
27
|
+
async function sketchfab (input) {
|
|
28
|
+
const { body, statusCode } = await got(getAvatarUrl(input), {
|
|
29
|
+
responseType: 'json',
|
|
30
|
+
throwHttpErrors: false
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
if (statusCode >= 400) return
|
|
34
|
+
|
|
35
|
+
return getAvatar(body)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
39
|
+
module.exports.getAvatar = getAvatar
|