@unavatar/core 3.60.0 → 3.62.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 +14 -0
- package/package.json +1 -1
- package/src/providers/gumroad.js +45 -0
- package/src/providers/index.js +4 -0
- package/src/providers/sketchfab.js +39 -0
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
- [Google](#google)
|
|
52
52
|
- [Google Play](#google-play)
|
|
53
53
|
- [Gravatar](#gravatar)
|
|
54
|
+
- [Gumroad](#gumroad)
|
|
54
55
|
- [Hevy](#hevy)
|
|
55
56
|
- [Hugging Face](#hugging-face)
|
|
56
57
|
- [Instagram](#instagram)
|
|
@@ -83,6 +84,7 @@
|
|
|
83
84
|
- [Reddit](#reddit)
|
|
84
85
|
- [Revolut](#revolut)
|
|
85
86
|
- [Roblox](#roblox)
|
|
87
|
+
- [Sketchfab](#sketchfab)
|
|
86
88
|
- [Snapchat](#snapchat)
|
|
87
89
|
- [SoundCloud](#soundcloud)
|
|
88
90
|
- [Spotify](#spotify)
|
|
@@ -838,6 +840,12 @@ When you pass an email address directly in the URL, it is visible in plain text
|
|
|
838
840
|
|
|
839
841
|
To avoid this, pass a pre-computed `MD5` or `SHA256` hash of the email instead. Unavatar detects the hash automatically and routes it to Gravatar, which natively supports both hash formats.
|
|
840
842
|
|
|
843
|
+
### Gumroad
|
|
844
|
+
|
|
845
|
+
Get any Gumroad creator's profile picture by their username (the subdomain of their store).
|
|
846
|
+
|
|
847
|
+
e.g., [unavatar.io/gumroad/sahil](https://unavatar.io/gumroad/sahil)
|
|
848
|
+
|
|
841
849
|
### Hevy
|
|
842
850
|
|
|
843
851
|
Get any Hevy user's profile picture by their username.
|
|
@@ -1060,6 +1068,12 @@ Available inputs:
|
|
|
1060
1068
|
- Username, e.g., [unavatar.io/roblox/builderman](https://unavatar.io/roblox/builderman)
|
|
1061
1069
|
- User ID, e.g., [unavatar.io/roblox/id:156](https://unavatar.io/roblox/id:156)
|
|
1062
1070
|
|
|
1071
|
+
### Sketchfab
|
|
1072
|
+
|
|
1073
|
+
Get any Sketchfab creator's profile picture by their username.
|
|
1074
|
+
|
|
1075
|
+
e.g., [unavatar.io/sketchfab/nasa](https://unavatar.io/sketchfab/nasa)
|
|
1076
|
+
|
|
1063
1077
|
### Snapchat
|
|
1064
1078
|
|
|
1065
1079
|
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.62.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { get } = require('lodash')
|
|
4
|
+
|
|
5
|
+
const SUBDOMAIN_REGEX = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i
|
|
6
|
+
const DEFAULT_AVATAR_MARKER = 'gumroad-default-avatar'
|
|
7
|
+
|
|
8
|
+
const parseInput = input =>
|
|
9
|
+
typeof input === 'string' && SUBDOMAIN_REGEX.test(input)
|
|
10
|
+
? input.toLowerCase()
|
|
11
|
+
: undefined
|
|
12
|
+
|
|
13
|
+
const getAvatarUrl = input => `https://${input}.gumroad.com/`
|
|
14
|
+
|
|
15
|
+
const getAvatar = ({ $, NOT_FOUND }) => {
|
|
16
|
+
const page = $('#app').attr('data-page')
|
|
17
|
+
if (!page) return
|
|
18
|
+
const avatarUrl = get(JSON.parse(page), [
|
|
19
|
+
'props',
|
|
20
|
+
'creator_profile',
|
|
21
|
+
'avatar_url'
|
|
22
|
+
])
|
|
23
|
+
if (!avatarUrl || avatarUrl.includes(DEFAULT_AVATAR_MARKER)) return NOT_FOUND
|
|
24
|
+
return avatarUrl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = ({ createHtmlProvider, NOT_FOUND }) => {
|
|
28
|
+
const htmlProvider = createHtmlProvider({
|
|
29
|
+
name: 'gumroad',
|
|
30
|
+
url: getAvatarUrl,
|
|
31
|
+
getter: $ => getAvatar({ $, NOT_FOUND })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const provider = (input, context) => {
|
|
35
|
+
const username = parseInput(input)
|
|
36
|
+
return username ? htmlProvider(username, context) : undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
provider.getUrl = getAvatarUrl
|
|
40
|
+
return provider
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports.parseInput = parseInput
|
|
44
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
45
|
+
module.exports.getAvatar = getAvatar
|
package/src/providers/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const providerTiers = {
|
|
|
31
31
|
'github',
|
|
32
32
|
'gitlab',
|
|
33
33
|
'google-play',
|
|
34
|
+
'gumroad',
|
|
34
35
|
'huggingface',
|
|
35
36
|
'hevy',
|
|
36
37
|
'instagram',
|
|
@@ -62,6 +63,7 @@ const providerTiers = {
|
|
|
62
63
|
'reddit',
|
|
63
64
|
'revolut',
|
|
64
65
|
'roblox',
|
|
66
|
+
'sketchfab',
|
|
65
67
|
'snapchat',
|
|
66
68
|
'soundcloud',
|
|
67
69
|
'spotify',
|
|
@@ -133,6 +135,7 @@ module.exports = ctx => {
|
|
|
133
135
|
google: require('./google')(ctx),
|
|
134
136
|
'google-play': require('./google-play')(ctx),
|
|
135
137
|
gravatar: require('./gravatar')(ctx),
|
|
138
|
+
gumroad: require('./gumroad')(ctx),
|
|
136
139
|
huggingface: require('./huggingface')(ctx),
|
|
137
140
|
hevy: require('./hevy')(ctx),
|
|
138
141
|
instagram: require('./instagram')(ctx),
|
|
@@ -165,6 +168,7 @@ module.exports = ctx => {
|
|
|
165
168
|
reddit: require('./reddit')(ctx),
|
|
166
169
|
revolut: require('./revolut')(ctx),
|
|
167
170
|
roblox: require('./roblox')(ctx),
|
|
171
|
+
sketchfab: require('./sketchfab')(ctx),
|
|
168
172
|
snapchat: require('./snapchat')(ctx),
|
|
169
173
|
soundcloud: require('./soundcloud')(ctx),
|
|
170
174
|
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
|