@unavatar/core 3.65.0 → 3.67.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
@@ -90,6 +90,7 @@
90
90
  - [Sketchfab](#sketchfab)
91
91
  - [Snapchat](#snapchat)
92
92
  - [SoundCloud](#soundcloud)
93
+ - [Speedrun](#speedrun)
93
94
  - [Spotify](#spotify)
94
95
  - [Stack Overflow](#stack-overflow)
95
96
  - [Steam](#steam)
@@ -105,6 +106,7 @@
105
106
  - [Twitch](#twitch)
106
107
  - [Venmo](#venmo)
107
108
  - [Vimeo](#vimeo)
109
+ - [Wattpad](#wattpad)
108
110
  - [Weibo](#weibo)
109
111
  - [WhatsApp](#whatsapp)
110
112
  - [Wise](#wise)
@@ -1119,6 +1121,12 @@ Get any SoundCloud artist's profile picture by their username.
1119
1121
 
1120
1122
  e.g., [unavatar.io/soundcloud/gorillaz](https://unavatar.io/soundcloud/gorillaz)
1121
1123
 
1124
+ ### Speedrun
1125
+
1126
+ Get any Speedrun.com runner's profile picture by their username or user ID.
1127
+
1128
+ e.g., [unavatar.io/speedrun/cheese](https://unavatar.io/speedrun/cheese)
1129
+
1122
1130
  ### Spotify
1123
1131
 
1124
1132
  Get artwork for any Spotify entity — users, artists, albums, playlists, shows, episodes, or tracks. Look up by username or Spotify ID.
@@ -1237,6 +1245,12 @@ Get any Vimeo user's profile picture by their username.
1237
1245
 
1238
1246
  e.g., [unavatar.io/vimeo/ladieswithlenses](https://unavatar.io/vimeo/ladieswithlenses)
1239
1247
 
1248
+ ### Wattpad
1249
+
1250
+ Get any Wattpad user's profile picture by their username.
1251
+
1252
+ e.g., [unavatar.io/wattpad/Wattpad](https://unavatar.io/wattpad/Wattpad)
1253
+
1240
1254
  ### Weibo
1241
1255
 
1242
1256
  Get any Weibo user's profile picture by numeric user ID or screen name.
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.65.0",
5
+ "version": "3.67.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -68,6 +68,7 @@ const providerTiers = {
68
68
  'sketchfab',
69
69
  'snapchat',
70
70
  'soundcloud',
71
+ 'speedrun',
71
72
  'spotify',
72
73
  'stackoverflow',
73
74
  'steam',
@@ -84,6 +85,7 @@ const providerTiers = {
84
85
  'twitch',
85
86
  'venmo',
86
87
  'vimeo',
88
+ 'wattpad',
87
89
  'weibo',
88
90
  'whatsapp',
89
91
  'wise',
@@ -176,6 +178,7 @@ module.exports = ctx => {
176
178
  sketchfab: require('./sketchfab')(ctx),
177
179
  snapchat: require('./snapchat')(ctx),
178
180
  soundcloud: require('./soundcloud')(ctx),
181
+ speedrun: require('./speedrun')(ctx),
179
182
  spotify: require('./spotify')(ctx),
180
183
  stackoverflow: require('./stackoverflow')(ctx),
181
184
  steam: require('./steam')(ctx),
@@ -192,6 +195,7 @@ module.exports = ctx => {
192
195
  twitch: require('./twitch')(ctx),
193
196
  venmo: require('./venmo')(ctx),
194
197
  vimeo: require('./vimeo')(ctx),
198
+ wattpad: require('./wattpad')(ctx),
195
199
  weibo: require('./weibo')(ctx),
196
200
  whatsapp: require('./whatsapp')(ctx),
197
201
  wise: require('./wise')(ctx),
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://www.speedrun.com/api/v1/users'
4
+ const FILE_EXTENSION_RE = /\.\w+$/
5
+
6
+ const getAvatarUrl = input => `${API_URL}/${encodeURIComponent(input)}`
7
+
8
+ const toStaticImageUrl = input => {
9
+ const url = new URL(input)
10
+ if (!FILE_EXTENSION_RE.test(url.pathname)) url.pathname += '.png'
11
+ return url.toString()
12
+ }
13
+
14
+ const getAvatar = body => {
15
+ const pic = body?.data?.assets?.image?.uri
16
+ return typeof pic === 'string' && pic ? toStaticImageUrl(pic) : undefined
17
+ }
18
+
19
+ module.exports = ({ got }) =>
20
+ async function speedrun (input) {
21
+ const { body, statusCode } = await got(getAvatarUrl(input), {
22
+ responseType: 'json',
23
+ throwHttpErrors: false
24
+ })
25
+
26
+ if (statusCode >= 400) return
27
+
28
+ return getAvatar(body)
29
+ }
30
+
31
+ module.exports.getAvatarUrl = getAvatarUrl
32
+ module.exports.getAvatar = getAvatar
@@ -0,0 +1,34 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://www.wattpad.com/api/v3/users'
4
+
5
+ const MAX_AVATAR_SIZE = 256
6
+
7
+ const AVATAR_SIZE_RE = /\.\d+(\.\d+\.\w+)$/
8
+
9
+ const STOCK_DEFAULT_AVATAR_RE = /\/useravatar\/[0-9a-f]\.\d+\.\w+$/
10
+
11
+ const getAvatarUrl = input =>
12
+ `${API_URL}/${encodeURIComponent(input.replace(/^@/, ''))}?fields=avatar`
13
+
14
+ const getAvatar = body => {
15
+ const avatar = body?.avatar
16
+ if (typeof avatar !== 'string' || !avatar) return
17
+ if (STOCK_DEFAULT_AVATAR_RE.test(avatar)) return
18
+ return avatar.replace(AVATAR_SIZE_RE, `.${MAX_AVATAR_SIZE}$1`)
19
+ }
20
+
21
+ module.exports = ({ got }) =>
22
+ async function wattpad (input) {
23
+ const { body, statusCode } = await got(getAvatarUrl(input), {
24
+ responseType: 'json',
25
+ throwHttpErrors: false
26
+ })
27
+
28
+ if (statusCode >= 400) return
29
+
30
+ return getAvatar(body)
31
+ }
32
+
33
+ module.exports.getAvatarUrl = getAvatarUrl
34
+ module.exports.getAvatar = getAvatar