@unavatar/core 3.55.0 → 3.57.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/index.js +4 -0
- package/src/providers/mixcloud.js +42 -0
- package/src/providers/osu.js +23 -0
package/README.md
CHANGED
|
@@ -61,10 +61,12 @@
|
|
|
61
61
|
- [Medium](#medium)
|
|
62
62
|
- [Microlink](#microlink)
|
|
63
63
|
- [Minecraft](#minecraft)
|
|
64
|
+
- [Mixcloud](#mixcloud)
|
|
64
65
|
- [NetEase Music](#netease-music)
|
|
65
66
|
- [npm](#npm)
|
|
66
67
|
- [OnlyFans](#onlyfans)
|
|
67
68
|
- [OpenStreetMap](#openstreetmap)
|
|
69
|
+
- [osu!](#osu)
|
|
68
70
|
- [Patreon](#patreon)
|
|
69
71
|
- [PayPal](#paypal)
|
|
70
72
|
- [Pinterest](#pinterest)
|
|
@@ -903,6 +905,12 @@ Available inputs:
|
|
|
903
905
|
- Username, e.g., [unavatar.io/minecraft/notch](https://unavatar.io/minecraft/notch)
|
|
904
906
|
- UUID, with or without dashes, e.g., [unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5](https://unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5)
|
|
905
907
|
|
|
908
|
+
### Mixcloud
|
|
909
|
+
|
|
910
|
+
Get any Mixcloud user's profile picture by their username.
|
|
911
|
+
|
|
912
|
+
e.g., [unavatar.io/mixcloud/spartacus](https://unavatar.io/mixcloud/spartacus)
|
|
913
|
+
|
|
906
914
|
### NetEase Music
|
|
907
915
|
|
|
908
916
|
Get any NetEase Music user's profile picture by their numeric user ID.
|
|
@@ -930,6 +938,15 @@ Available inputs:
|
|
|
930
938
|
- Numeric user ID, e.g., [unavatar.io/openstreetmap/98672](https://unavatar.io/openstreetmap/98672)
|
|
931
939
|
- Username, e.g., [unavatar.io/openstreetmap/Terence%20Eden](https://unavatar.io/openstreetmap/Terence%20Eden)
|
|
932
940
|
|
|
941
|
+
### osu!
|
|
942
|
+
|
|
943
|
+
Get any osu! player's profile picture by their username or numeric user ID.
|
|
944
|
+
|
|
945
|
+
Available inputs:
|
|
946
|
+
|
|
947
|
+
- Username, e.g., [unavatar.io/osu/peppy](https://unavatar.io/osu/peppy)
|
|
948
|
+
- Numeric user ID, e.g., [unavatar.io/osu/7562902](https://unavatar.io/osu/7562902)
|
|
949
|
+
|
|
933
950
|
### Patreon
|
|
934
951
|
|
|
935
952
|
Get any Patreon creator'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.57.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
package/src/providers/index.js
CHANGED
|
@@ -40,10 +40,12 @@ const providerTiers = {
|
|
|
40
40
|
'mastodon',
|
|
41
41
|
'medium',
|
|
42
42
|
'minecraft',
|
|
43
|
+
'mixcloud',
|
|
43
44
|
'netease-music',
|
|
44
45
|
'npm',
|
|
45
46
|
'onlyfans',
|
|
46
47
|
'openstreetmap',
|
|
48
|
+
'osu',
|
|
47
49
|
'patreon',
|
|
48
50
|
'paypal',
|
|
49
51
|
'pinterest',
|
|
@@ -137,10 +139,12 @@ module.exports = ctx => {
|
|
|
137
139
|
medium: require('./medium')(ctx),
|
|
138
140
|
microlink: require('./microlink')(ctx),
|
|
139
141
|
minecraft: require('./minecraft')(ctx),
|
|
142
|
+
mixcloud: require('./mixcloud')(ctx),
|
|
140
143
|
'netease-music': require('./netease-music')(ctx),
|
|
141
144
|
npm: require('./npm')(ctx),
|
|
142
145
|
onlyfans: require('./onlyfans')(ctx),
|
|
143
146
|
openstreetmap: require('./openstreetmap')(ctx),
|
|
147
|
+
osu: require('./osu')(ctx),
|
|
144
148
|
patreon: require('./patreon')(ctx),
|
|
145
149
|
paypal: require('./paypal')(ctx),
|
|
146
150
|
pinterest: require('./pinterest')(ctx),
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'https://api.mixcloud.com'
|
|
4
|
+
|
|
5
|
+
const SQUARE_SIZE_RE = /\/unsafe\/(\d+)x\1\//
|
|
6
|
+
|
|
7
|
+
const DEFAULT_PICTURE_RE = /\/unsafe\/\d+x\d+\/defaults\//
|
|
8
|
+
|
|
9
|
+
const parseInput = input => input.replace(/^@/, '')
|
|
10
|
+
|
|
11
|
+
const getAvatarUrl = input => `${API_URL}/${encodeURIComponent(input)}/`
|
|
12
|
+
|
|
13
|
+
const getSquareSize = url => Number(SQUARE_SIZE_RE.exec(url)?.[1] ?? 0)
|
|
14
|
+
|
|
15
|
+
const getAvatar = body => {
|
|
16
|
+
const pictures = Object.values(body?.pictures ?? {}).filter(
|
|
17
|
+
url => typeof url === 'string' && getSquareSize(url) > 0
|
|
18
|
+
)
|
|
19
|
+
if (pictures.length === 0) return
|
|
20
|
+
|
|
21
|
+
const largest = pictures.reduce((best, url) =>
|
|
22
|
+
getSquareSize(url) > getSquareSize(best) ? url : best
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
return DEFAULT_PICTURE_RE.test(largest) ? undefined : largest
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = ({ got }) =>
|
|
29
|
+
async function mixcloud (input) {
|
|
30
|
+
const { body, statusCode } = await got(getAvatarUrl(parseInput(input)), {
|
|
31
|
+
responseType: 'json',
|
|
32
|
+
throwHttpErrors: false
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
if (statusCode >= 400) return
|
|
36
|
+
|
|
37
|
+
return getAvatar(body)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports.parseInput = parseInput
|
|
41
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
42
|
+
module.exports.getAvatar = getAvatar
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const PROFILE_URL = 'https://osu.ppy.sh/users'
|
|
4
|
+
const UPLOADED_AVATAR_ORIGIN = 'https://a.ppy.sh/'
|
|
5
|
+
|
|
6
|
+
const isUploadedAvatar = url => url.startsWith(UPLOADED_AVATAR_ORIGIN)
|
|
7
|
+
|
|
8
|
+
const getAvatarUrl = input => `${PROFILE_URL}/${encodeURIComponent(input)}`
|
|
9
|
+
|
|
10
|
+
const getAvatar = ({ $, getOgImage, NOT_FOUND }) => {
|
|
11
|
+
const image = getOgImage($)
|
|
12
|
+
return image && isUploadedAvatar(image) ? image : NOT_FOUND
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = ({ createHtmlProvider, getOgImage, NOT_FOUND }) =>
|
|
16
|
+
createHtmlProvider({
|
|
17
|
+
name: 'osu',
|
|
18
|
+
url: getAvatarUrl,
|
|
19
|
+
getter: $ => getAvatar({ $, getOgImage, NOT_FOUND })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
23
|
+
module.exports.getAvatar = getAvatar
|