@unavatar/core 3.52.0 → 3.55.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 CHANGED
@@ -27,10 +27,12 @@
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)
33
34
  - [Cursor](#cursor)
35
+ - [Dailymotion](#dailymotion)
34
36
  - [Deezer](#deezer)
35
37
  - [DeviantArt](#deviantart)
36
38
  - [Discord](#discord)
@@ -58,6 +60,7 @@
58
60
  - [Mastodon](#mastodon)
59
61
  - [Medium](#medium)
60
62
  - [Microlink](#microlink)
63
+ - [Minecraft](#minecraft)
61
64
  - [NetEase Music](#netease-music)
62
65
  - [npm](#npm)
63
66
  - [OnlyFans](#onlyfans)
@@ -624,6 +627,12 @@ Get any Cash App user's profile picture by their Cashtag.
624
627
 
625
628
  e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
626
629
 
630
+ ### Chess.com
631
+
632
+ Get any Chess.com player's profile picture by their username.
633
+
634
+ e.g., [unavatar.io/chesscom/hikaru](https://unavatar.io/chesscom/hikaru)
635
+
627
636
  ### Codeforces
628
637
 
629
638
  Get any Codeforces user's profile picture by their handle.
@@ -648,6 +657,12 @@ Get any Cursor user's profile picture by their username.
648
657
 
649
658
  e.g., [unavatar.io/cursor/leerob](https://unavatar.io/cursor/leerob)
650
659
 
660
+ ### Dailymotion
661
+
662
+ Get any Dailymotion user's profile picture by their username or user ID.
663
+
664
+ e.g., [unavatar.io/dailymotion/dailymotion](https://unavatar.io/dailymotion/dailymotion)
665
+
651
666
  ### Deezer
652
667
 
653
668
  Get artwork for any Deezer artist, album, playlist, or track by ID.
@@ -879,6 +894,15 @@ Extract the logo or representative image from any URL. The page is rendered and
879
894
 
880
895
  e.g., [unavatar.io/microlink/microlink.io](https://unavatar.io/microlink/microlink.io)
881
896
 
897
+ ### Minecraft
898
+
899
+ Get any Minecraft Java Edition player's face by their username or UUID. The player is resolved through Mojang first, so unknown players return no avatar, and the face is rendered by [mc-heads.net](https://mc-heads.net).
900
+
901
+ Available inputs:
902
+
903
+ - Username, e.g., [unavatar.io/minecraft/notch](https://unavatar.io/minecraft/notch)
904
+ - 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
+
882
906
  ### NetEase Music
883
907
 
884
908
  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.52.0",
5
+ "version": "3.55.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
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://api.dailymotion.com/user'
4
+
5
+ const PLACEHOLDER_AVATAR_PATH_PREFIX = '/d/'
6
+
7
+ const isPlaceholderAvatar = url =>
8
+ new URL(url).pathname.startsWith(PLACEHOLDER_AVATAR_PATH_PREFIX)
9
+
10
+ const getAvatarUrl = input =>
11
+ `${API_URL}/${encodeURIComponent(input)}?fields=avatar_720_url`
12
+
13
+ const getAvatar = body => {
14
+ const url = body?.avatar_720_url
15
+ return typeof url === 'string' && url && !isPlaceholderAvatar(url)
16
+ ? url
17
+ : undefined
18
+ }
19
+
20
+ module.exports = ({ got }) =>
21
+ async function dailymotion (input) {
22
+ const { body, statusCode } = await got(getAvatarUrl(input), {
23
+ responseType: 'json',
24
+ throwHttpErrors: false
25
+ })
26
+
27
+ if (statusCode >= 400) return
28
+
29
+ return getAvatar(body)
30
+ }
31
+
32
+ module.exports.getAvatarUrl = getAvatarUrl
33
+ module.exports.getAvatar = getAvatar
@@ -12,10 +12,12 @@ const providerTiers = {
12
12
  'bluesky',
13
13
  'buymeacoffee',
14
14
  'cashapp',
15
+ 'chesscom',
15
16
  'codeforces',
16
17
  'codepen',
17
18
  'cults3d',
18
19
  'cursor',
20
+ 'dailymotion',
19
21
  'deezer',
20
22
  'deviantart',
21
23
  'discord',
@@ -37,6 +39,7 @@ const providerTiers = {
37
39
  'linkedin',
38
40
  'mastodon',
39
41
  'medium',
42
+ 'minecraft',
40
43
  'netease-music',
41
44
  'npm',
42
45
  'onlyfans',
@@ -102,10 +105,12 @@ module.exports = ctx => {
102
105
  bluesky: require('./bluesky')(ctx),
103
106
  buymeacoffee: require('./buymeacoffee')(ctx),
104
107
  cashapp: require('./cashapp')(ctx),
108
+ chesscom: require('./chesscom')(ctx),
105
109
  codeforces: require('./codeforces')(ctx),
106
110
  codepen: require('./codepen')(ctx),
107
111
  cults3d: require('./cults3d')(ctx),
108
112
  cursor: require('./cursor')(ctx),
113
+ dailymotion: require('./dailymotion')(ctx),
109
114
  deezer: require('./deezer')(ctx),
110
115
  deviantart: require('./deviantart')(ctx),
111
116
  discord: require('./discord')(ctx),
@@ -131,6 +136,7 @@ module.exports = ctx => {
131
136
  mastodon: require('./mastodon')(ctx),
132
137
  medium: require('./medium')(ctx),
133
138
  microlink: require('./microlink')(ctx),
139
+ minecraft: require('./minecraft')(ctx),
134
140
  'netease-music': require('./netease-music')(ctx),
135
141
  npm: require('./npm')(ctx),
136
142
  onlyfans: require('./onlyfans')(ctx),
@@ -0,0 +1,40 @@
1
+ 'use strict'
2
+
3
+ const MOJANG_PROFILE_API_URL =
4
+ 'https://api.minecraftservices.com/minecraft/profile/lookup'
5
+ const MC_HEADS_AVATAR_URL = 'https://mc-heads.net/avatar'
6
+
7
+ const UUID_RE =
8
+ /^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i
9
+
10
+ const parseInput = input =>
11
+ UUID_RE.test(input)
12
+ ? { type: 'uuid', value: input.replace(/-/g, '').toLowerCase() }
13
+ : { type: 'name', value: input }
14
+
15
+ const getAvatarUrl = input => {
16
+ const { type, value } = parseInput(input)
17
+ const path = type === 'uuid' ? value : `name/${encodeURIComponent(value)}`
18
+ return `${MOJANG_PROFILE_API_URL}/${path}`
19
+ }
20
+
21
+ const getAvatar = (body, size) =>
22
+ typeof body?.id === 'string' && body.id
23
+ ? `${MC_HEADS_AVATAR_URL}/${body.id}/${size}`
24
+ : undefined
25
+
26
+ module.exports = ({ constants, got }) =>
27
+ async function minecraft (input) {
28
+ const { statusCode, body } = await got(getAvatarUrl(input), {
29
+ responseType: 'json',
30
+ throwHttpErrors: false
31
+ })
32
+
33
+ if (statusCode >= 400) return
34
+
35
+ return getAvatar(body, constants.AVATAR_SIZE)
36
+ }
37
+
38
+ module.exports.parseInput = parseInput
39
+ module.exports.getAvatarUrl = getAvatarUrl
40
+ module.exports.getAvatar = getAvatar