@unavatar/core 3.57.0 → 3.58.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/devto.js +67 -0
- package/src/providers/index.js +2 -0
package/README.md
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
- [Cursor](#cursor)
|
|
35
35
|
- [Dailymotion](#dailymotion)
|
|
36
36
|
- [Deezer](#deezer)
|
|
37
|
+
- [DEV](#dev)
|
|
37
38
|
- [DeviantArt](#deviantart)
|
|
38
39
|
- [Discord](#discord)
|
|
39
40
|
- [Docker Hub](#docker-hub)
|
|
@@ -680,6 +681,12 @@ Available inputs:
|
|
|
680
681
|
- `playlist`: [unavatar.io/deezer/playlist:908622995](https://unavatar.io/deezer/playlist:908622995)
|
|
681
682
|
- `track`: [unavatar.io/deezer/track:3135556](https://unavatar.io/deezer/track:3135556)
|
|
682
683
|
|
|
684
|
+
### DEV
|
|
685
|
+
|
|
686
|
+
Get any [DEV](https://dev.to) user's profile picture by username, or an organization's logo by its slug.
|
|
687
|
+
|
|
688
|
+
e.g., [unavatar.io/devto/ben](https://unavatar.io/devto/ben)
|
|
689
|
+
|
|
683
690
|
### DeviantArt
|
|
684
691
|
|
|
685
692
|
Get any DeviantArt user'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.58.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const API_URL = 'https://dev.to/api'
|
|
4
|
+
|
|
5
|
+
const PLACEHOLDER_URL =
|
|
6
|
+
'https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png'
|
|
7
|
+
|
|
8
|
+
const RESIZED_IMAGE_RE = /^(.+\/dynamic\/image\/)([^/]+)\/(https?%3A%2F%2F.+)$/i
|
|
9
|
+
|
|
10
|
+
const DIMENSION_RE = /\b(width|height)=\d+/g
|
|
11
|
+
|
|
12
|
+
const parseInput = input => input.trim().replace(/^@/, '').toLowerCase()
|
|
13
|
+
|
|
14
|
+
const getUserAvatarUrl = input =>
|
|
15
|
+
`${API_URL}/users/by_username?url=${encodeURIComponent(input)}`
|
|
16
|
+
|
|
17
|
+
const getOrganizationAvatarUrl = input =>
|
|
18
|
+
`${API_URL}/organizations/${encodeURIComponent(input)}`
|
|
19
|
+
|
|
20
|
+
const getAvatar = ({ body, size }) => {
|
|
21
|
+
const image = body?.profile_image
|
|
22
|
+
if (typeof image !== 'string' || !image) return
|
|
23
|
+
|
|
24
|
+
const match = RESIZED_IMAGE_RE.exec(image)
|
|
25
|
+
const originalUrl = match ? decodeURIComponent(match[3]) : image
|
|
26
|
+
if (originalUrl === PLACEHOLDER_URL) return
|
|
27
|
+
if (!match) return image
|
|
28
|
+
|
|
29
|
+
const [, prefix, options, encodedOriginalUrl] = match
|
|
30
|
+
const resizedOptions = options.replace(DIMENSION_RE, `$1=${size}`)
|
|
31
|
+
return `${prefix}${resizedOptions}/${encodedOriginalUrl}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fetchAvatarUrl = async ({ got, url, size }) => {
|
|
35
|
+
const { statusCode, body } = await got(url, {
|
|
36
|
+
responseType: 'json',
|
|
37
|
+
throwHttpErrors: false
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
if (statusCode >= 400) return
|
|
41
|
+
|
|
42
|
+
return getAvatar({ body, size })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = ({ constants, got }) =>
|
|
46
|
+
async function devto (input) {
|
|
47
|
+
const username = parseInput(input)
|
|
48
|
+
const size = constants.AVATAR_SIZE
|
|
49
|
+
|
|
50
|
+
const userAvatarUrl = await fetchAvatarUrl({
|
|
51
|
+
got,
|
|
52
|
+
size,
|
|
53
|
+
url: getUserAvatarUrl(username)
|
|
54
|
+
})
|
|
55
|
+
if (userAvatarUrl) return userAvatarUrl
|
|
56
|
+
|
|
57
|
+
return fetchAvatarUrl({
|
|
58
|
+
got,
|
|
59
|
+
size,
|
|
60
|
+
url: getOrganizationAvatarUrl(username)
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports.parseInput = parseInput
|
|
65
|
+
module.exports.getUserAvatarUrl = getUserAvatarUrl
|
|
66
|
+
module.exports.getOrganizationAvatarUrl = getOrganizationAvatarUrl
|
|
67
|
+
module.exports.getAvatar = getAvatar
|
package/src/providers/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const providerTiers = {
|
|
|
20
20
|
'dailymotion',
|
|
21
21
|
'deezer',
|
|
22
22
|
'deviantart',
|
|
23
|
+
'devto',
|
|
23
24
|
'discord',
|
|
24
25
|
'dockerhub',
|
|
25
26
|
'dribbble',
|
|
@@ -115,6 +116,7 @@ module.exports = ctx => {
|
|
|
115
116
|
dailymotion: require('./dailymotion')(ctx),
|
|
116
117
|
deezer: require('./deezer')(ctx),
|
|
117
118
|
deviantart: require('./deviantart')(ctx),
|
|
119
|
+
devto: require('./devto')(ctx),
|
|
118
120
|
discord: require('./discord')(ctx),
|
|
119
121
|
dockerhub: require('./dockerhub')(ctx),
|
|
120
122
|
dribbble: require('./dribbble')(ctx),
|