@unavatar/core 3.63.0 → 3.64.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
@@ -42,6 +42,7 @@
42
42
  - [Domain](#domain)
43
43
  - [Dribbble](#dribbble)
44
44
  - [DuckDuckGo](#duckduckgo)
45
+ - [Duolingo](#duolingo)
45
46
  - [Email](#email)
46
47
  - [Facebook](#facebook)
47
48
  - [Flickr](#flickr)
@@ -738,6 +739,12 @@ Get the favicon or logo for any domain via DuckDuckGo's icon service. Useful as
738
739
 
739
740
  e.g., [unavatar.io/duckduckgo/microsoft.com](https://unavatar.io/duckduckgo/microsoft.com)
740
741
 
742
+ ### Duolingo
743
+
744
+ Get any Duolingo learner's profile picture by their username.
745
+
746
+ e.g., [unavatar.io/duolingo/luis](https://unavatar.io/duolingo/luis)
747
+
741
748
  ### Email
742
749
 
743
750
  Resolve user avatars from an email address with a single URL. The `/email/:key` route uses the same provider chain as a bare `/user@domain` path: the service tries Gravatar and GitHub, then Libravatar, then BIMI until one returns an image. No API keys and no SDK are required.
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.63.0",
5
+ "version": "3.64.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,37 @@
1
+ 'use strict'
2
+
3
+ const stringify = require('../util/stringify')
4
+
5
+ const ORIGIN = 'https://www.duolingo.com'
6
+ const API_URL = `${ORIGIN}/2017-06-30/users`
7
+ const PICTURE_SIZE = 'xxlarge'
8
+ const DEFAULT_PICTURE_PATH_RE = /^\/avatar\/default_\d+\/?$/
9
+
10
+ const getAvatarUrl = input =>
11
+ `${API_URL}?${stringify({ username: input, fields: 'users{picture}' })}`
12
+
13
+ const getAvatar = body => {
14
+ const pic = body?.users?.[0]?.picture
15
+ if (typeof pic !== 'string' || !pic) return
16
+
17
+ const url = new URL(pic, ORIGIN)
18
+ if (DEFAULT_PICTURE_PATH_RE.test(url.pathname)) return
19
+
20
+ url.pathname = `${url.pathname.replace(/\/$/, '')}/${PICTURE_SIZE}`
21
+ return url.toString()
22
+ }
23
+
24
+ module.exports = ({ got }) =>
25
+ async function duolingo (input) {
26
+ const { body, statusCode } = await got(getAvatarUrl(input), {
27
+ responseType: 'json',
28
+ throwHttpErrors: false
29
+ })
30
+
31
+ if (statusCode >= 400) return
32
+
33
+ return getAvatar(body)
34
+ }
35
+
36
+ module.exports.getAvatarUrl = getAvatarUrl
37
+ module.exports.getAvatar = getAvatar
@@ -25,6 +25,7 @@ const providerTiers = {
25
25
  'discord',
26
26
  'dockerhub',
27
27
  'dribbble',
28
+ 'duolingo',
28
29
  'facebook',
29
30
  'flickr',
30
31
  'gitee',
@@ -127,6 +128,7 @@ module.exports = ctx => {
127
128
  dockerhub: require('./dockerhub')(ctx),
128
129
  dribbble: require('./dribbble')(ctx),
129
130
  duckduckgo: require('./duckduckgo')(ctx),
131
+ duolingo: require('./duolingo')(ctx),
130
132
  facebook: require('./facebook')(ctx),
131
133
  flickr: require('./flickr')(ctx),
132
134
  gitee: require('./gitee')(ctx),