@unavatar/core 3.32.5 → 3.32.7
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/package.json +1 -1
- package/src/providers/dockerhub.js +14 -2
- package/src/providers/npm.js +52 -14
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.32.
|
|
5
|
+
"version": "3.32.7",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -3,8 +3,17 @@
|
|
|
3
3
|
const API_URL = 'https://hub.docker.com/v2/users'
|
|
4
4
|
|
|
5
5
|
const getAvatarUrl = input => `${API_URL}/${encodeURIComponent(input)}/`
|
|
6
|
+
const getMaxResGravatarUrl = ({ constants, input }) => {
|
|
7
|
+
const url = new URL(input)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
// `d=404` makes missing avatars fail instead of falling back to placeholders.
|
|
10
|
+
url.searchParams.set('s', String(constants.AVATAR_SIZE))
|
|
11
|
+
url.searchParams.set('d', '404')
|
|
12
|
+
|
|
13
|
+
return url.toString()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = ({ constants, got }) =>
|
|
8
17
|
async function dockerhub (input) {
|
|
9
18
|
const { body, statusCode } = await got(getAvatarUrl(input), {
|
|
10
19
|
responseType: 'json',
|
|
@@ -13,7 +22,10 @@ module.exports = ({ got }) =>
|
|
|
13
22
|
|
|
14
23
|
if (statusCode >= 400) return
|
|
15
24
|
|
|
16
|
-
|
|
25
|
+
if (!body?.gravatar_url) return undefined
|
|
26
|
+
|
|
27
|
+
return getMaxResGravatarUrl({ constants, input: body.gravatar_url })
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
module.exports.getAvatarUrl = getAvatarUrl
|
|
31
|
+
module.exports.getMaxResGravatarUrl = getMaxResGravatarUrl
|
package/src/providers/npm.js
CHANGED
|
@@ -1,24 +1,62 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { getAvatarUrl: getGitHubAvatarUrl } = require('./github')
|
|
4
|
+
const stringify = require('../util/stringify')
|
|
5
|
+
|
|
6
|
+
const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
|
|
7
|
+
const GITLAB_API_URL = 'https://gitlab.com/api/v4'
|
|
4
8
|
|
|
5
9
|
const stripAtPrefix = input => input.replace(/^@/, '')
|
|
6
10
|
|
|
7
|
-
const
|
|
11
|
+
const GITHUB_RE = /github\.com[/:]([^/]+)/
|
|
12
|
+
const GITLAB_RE = /gitlab\.com[/:]([^/]+)/
|
|
13
|
+
|
|
14
|
+
const getRepoUsername = objects => {
|
|
15
|
+
let gitlabFallback
|
|
16
|
+
|
|
17
|
+
for (const { package: pkg } of objects) {
|
|
18
|
+
const repo = pkg?.links?.repository
|
|
19
|
+
if (!repo) continue
|
|
8
20
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
if (!src) return
|
|
21
|
+
const githubMatch = GITHUB_RE.exec(repo)
|
|
22
|
+
if (githubMatch) return { platform: 'github', username: githubMatch[1] }
|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
if (!gitlabFallback) {
|
|
25
|
+
const gitlabMatch = GITLAB_RE.exec(repo)
|
|
26
|
+
if (gitlabMatch) { gitlabFallback = { platform: 'gitlab', username: gitlabMatch[1] } }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return gitlabFallback
|
|
14
31
|
}
|
|
15
32
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
const getGitLabAvatarUrl = async ({ got, username }) => {
|
|
34
|
+
const { body } = await got(
|
|
35
|
+
`${GITLAB_API_URL}/users?username=${encodeURIComponent(username)}`,
|
|
36
|
+
{ responseType: 'json' }
|
|
37
|
+
)
|
|
38
|
+
return body?.[0]?.avatar_url
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = ({ constants, got }) =>
|
|
42
|
+
async function npm (input) {
|
|
43
|
+
const username = stripAtPrefix(input)
|
|
44
|
+
const url = `${NPM_REGISTRY_URL}/-/v1/search?${stringify({
|
|
45
|
+
text: `maintainer:${username}`,
|
|
46
|
+
size: 5
|
|
47
|
+
})}`
|
|
48
|
+
|
|
49
|
+
const { body } = await got(url, { responseType: 'json' })
|
|
50
|
+
const objects = (body?.objects ?? []).filter(
|
|
51
|
+
o => o.package?.publisher?.username === username
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const match = getRepoUsername(objects)
|
|
55
|
+
if (!match) return
|
|
56
|
+
|
|
57
|
+
if (match.platform === 'github') {
|
|
58
|
+
return getGitHubAvatarUrl({ constants, input: match.username })
|
|
59
|
+
}
|
|
22
60
|
|
|
23
|
-
|
|
24
|
-
|
|
61
|
+
return getGitLabAvatarUrl({ got, username: match.username })
|
|
62
|
+
}
|