@unavatar/core 3.55.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 +7 -0
- package/package.json +1 -1
- package/src/providers/index.js +2 -0
- package/src/providers/mixcloud.js +42 -0
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@
|
|
|
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)
|
|
@@ -903,6 +904,12 @@ Available inputs:
|
|
|
903
904
|
- Username, e.g., [unavatar.io/minecraft/notch](https://unavatar.io/minecraft/notch)
|
|
904
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)
|
|
905
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
|
+
|
|
906
913
|
### NetEase Music
|
|
907
914
|
|
|
908
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",
|
package/src/providers/index.js
CHANGED
|
@@ -40,6 +40,7 @@ const providerTiers = {
|
|
|
40
40
|
'mastodon',
|
|
41
41
|
'medium',
|
|
42
42
|
'minecraft',
|
|
43
|
+
'mixcloud',
|
|
43
44
|
'netease-music',
|
|
44
45
|
'npm',
|
|
45
46
|
'onlyfans',
|
|
@@ -137,6 +138,7 @@ module.exports = ctx => {
|
|
|
137
138
|
medium: require('./medium')(ctx),
|
|
138
139
|
microlink: require('./microlink')(ctx),
|
|
139
140
|
minecraft: require('./minecraft')(ctx),
|
|
141
|
+
mixcloud: require('./mixcloud')(ctx),
|
|
140
142
|
'netease-music': require('./netease-music')(ctx),
|
|
141
143
|
npm: require('./npm')(ctx),
|
|
142
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
|