@unavatar/core 3.54.0 → 3.56.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/chesscom.js +26 -0
- package/src/providers/index.js +4 -0
- package/src/providers/mixcloud.js +42 -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
|
+
- [Chess.com](#chesscom)
|
|
30
31
|
- [Codeforces](#codeforces)
|
|
31
32
|
- [CodePen](#codepen)
|
|
32
33
|
- [Cults3D](#cults3d)
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
- [Medium](#medium)
|
|
61
62
|
- [Microlink](#microlink)
|
|
62
63
|
- [Minecraft](#minecraft)
|
|
64
|
+
- [Mixcloud](#mixcloud)
|
|
63
65
|
- [NetEase Music](#netease-music)
|
|
64
66
|
- [npm](#npm)
|
|
65
67
|
- [OnlyFans](#onlyfans)
|
|
@@ -626,6 +628,12 @@ Get any Cash App user's profile picture by their Cashtag.
|
|
|
626
628
|
|
|
627
629
|
e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
|
|
628
630
|
|
|
631
|
+
### Chess.com
|
|
632
|
+
|
|
633
|
+
Get any Chess.com player's profile picture by their username.
|
|
634
|
+
|
|
635
|
+
e.g., [unavatar.io/chesscom/hikaru](https://unavatar.io/chesscom/hikaru)
|
|
636
|
+
|
|
629
637
|
### Codeforces
|
|
630
638
|
|
|
631
639
|
Get any Codeforces user's profile picture by their handle.
|
|
@@ -896,6 +904,12 @@ Available inputs:
|
|
|
896
904
|
- Username, e.g., [unavatar.io/minecraft/notch](https://unavatar.io/minecraft/notch)
|
|
897
905
|
- UUID, with or without dashes, e.g., [unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5](https://unavatar.io/minecraft/069a79f4-44e9-4726-a5be-fca90e38aaf5)
|
|
898
906
|
|
|
907
|
+
### Mixcloud
|
|
908
|
+
|
|
909
|
+
Get any Mixcloud user's profile picture by their username.
|
|
910
|
+
|
|
911
|
+
e.g., [unavatar.io/mixcloud/spartacus](https://unavatar.io/mixcloud/spartacus)
|
|
912
|
+
|
|
899
913
|
### NetEase Music
|
|
900
914
|
|
|
901
915
|
Get any NetEase Music user's profile picture by their numeric user ID.
|
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.56.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'https://api.chess.com/pub/player'
|
|
4
|
+
|
|
5
|
+
const getAvatarUrl = input =>
|
|
6
|
+
`${API_URL}/${encodeURIComponent(input.toLowerCase())}`
|
|
7
|
+
|
|
8
|
+
const getAvatar = body => {
|
|
9
|
+
const pic = body?.avatar
|
|
10
|
+
return typeof pic === 'string' && pic ? pic : undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = ({ got }) =>
|
|
14
|
+
async function chesscom (input) {
|
|
15
|
+
const { body, statusCode } = await got(getAvatarUrl(input), {
|
|
16
|
+
responseType: 'json',
|
|
17
|
+
throwHttpErrors: false
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
if (statusCode >= 400) return
|
|
21
|
+
|
|
22
|
+
return getAvatar(body)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
26
|
+
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
|
+
'chesscom',
|
|
15
16
|
'codeforces',
|
|
16
17
|
'codepen',
|
|
17
18
|
'cults3d',
|
|
@@ -39,6 +40,7 @@ const providerTiers = {
|
|
|
39
40
|
'mastodon',
|
|
40
41
|
'medium',
|
|
41
42
|
'minecraft',
|
|
43
|
+
'mixcloud',
|
|
42
44
|
'netease-music',
|
|
43
45
|
'npm',
|
|
44
46
|
'onlyfans',
|
|
@@ -104,6 +106,7 @@ module.exports = ctx => {
|
|
|
104
106
|
bluesky: require('./bluesky')(ctx),
|
|
105
107
|
buymeacoffee: require('./buymeacoffee')(ctx),
|
|
106
108
|
cashapp: require('./cashapp')(ctx),
|
|
109
|
+
chesscom: require('./chesscom')(ctx),
|
|
107
110
|
codeforces: require('./codeforces')(ctx),
|
|
108
111
|
codepen: require('./codepen')(ctx),
|
|
109
112
|
cults3d: require('./cults3d')(ctx),
|
|
@@ -135,6 +138,7 @@ module.exports = ctx => {
|
|
|
135
138
|
medium: require('./medium')(ctx),
|
|
136
139
|
microlink: require('./microlink')(ctx),
|
|
137
140
|
minecraft: require('./minecraft')(ctx),
|
|
141
|
+
mixcloud: require('./mixcloud')(ctx),
|
|
138
142
|
'netease-music': require('./netease-music')(ctx),
|
|
139
143
|
npm: require('./npm')(ctx),
|
|
140
144
|
onlyfans: require('./onlyfans')(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
|