@unavatar/core 3.67.0 → 3.68.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
@@ -62,6 +62,7 @@
62
62
  - [Keybase](#keybase)
63
63
  - [Kick](#kick)
64
64
  - [Ko-fi](#ko-fi)
65
+ - [Lemmy](#lemmy)
65
66
  - [Libravatar](#libravatar)
66
67
  - [LinkedIn](#linkedin)
67
68
  - [Mastodon](#mastodon)
@@ -918,6 +919,12 @@ Get any Ko-fi page's profile picture by the creator username.
918
919
 
919
920
  e.g., [unavatar.io/ko-fi/geekshock](https://unavatar.io/ko-fi/geekshock)
920
921
 
922
+ ### Lemmy
923
+
924
+ Get any Lemmy user's profile picture from any instance using the public user API. Pass the handle as `user@instance` so the account resolves on the correct home instance.
925
+
926
+ e.g., [unavatar.io/lemmy/ruud@lemmy.world](https://unavatar.io/lemmy/ruud@lemmy.world)
927
+
921
928
  ### Libravatar
922
929
 
923
930
  Resolve avatars via [Libravatar](https://www.libravatar.org), the federated, open source alternative to Gravatar, using a plain email or a precomputed hash. Emails are trimmed, lowercased, and hashed with SHA-256; 64-hex SHA-256 and 32-hex MD5 values are passed through (normalized to lowercase).
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.67.0",
5
+ "version": "3.68.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -42,6 +42,7 @@ const providerTiers = {
42
42
  'keybase',
43
43
  'kick',
44
44
  'ko-fi',
45
+ 'lemmy',
45
46
  'linkedin',
46
47
  'mastodon',
47
48
  'medium',
@@ -150,6 +151,7 @@ module.exports = ctx => {
150
151
  keybase: require('./keybase')(ctx),
151
152
  kick: require('./kick')(ctx),
152
153
  'ko-fi': require('./ko-fi')(ctx),
154
+ lemmy: require('./lemmy')(ctx),
153
155
  libravatar: require('./libravatar')(ctx),
154
156
  linkedin: require('./linkedin')(ctx),
155
157
  mastodon: require('./mastodon')(ctx),
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+ const { parseInput } = require('./mastodon')
4
+
5
+ const getAvatarUrl = ({ username, server }) =>
6
+ `https://${server}/api/v3/user?username=${encodeURIComponent(username)}`
7
+
8
+ const getAvatar = body => {
9
+ const pic = body?.person_view?.person?.avatar
10
+ return typeof pic === 'string' && pic ? pic : undefined
11
+ }
12
+
13
+ module.exports = ({ got, isReservedIp }) =>
14
+ async function lemmy (input) {
15
+ const parsed = parseInput(input)
16
+ if (!parsed) return
17
+
18
+ if (await isReservedIp(parsed.server)) return
19
+
20
+ const { statusCode, body } = await got(getAvatarUrl(parsed), {
21
+ responseType: 'json',
22
+ throwHttpErrors: false
23
+ })
24
+
25
+ if (statusCode >= 400) return
26
+
27
+ return getAvatar(body)
28
+ }
29
+
30
+ module.exports.parseInput = parseInput
31
+ module.exports.getAvatarUrl = getAvatarUrl
32
+ module.exports.getAvatar = getAvatar