@unavatar/core 3.49.9 → 3.50.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
@@ -27,6 +27,7 @@
27
27
  - [Bluesky](#bluesky)
28
28
  - [Buy Me a Coffee](#buy-me-a-coffee)
29
29
  - [Cash App](#cash-app)
30
+ - [Codeforces](#codeforces)
30
31
  - [CodePen](#codepen)
31
32
  - [Cults3D](#cults3d)
32
33
  - [Cursor](#cursor)
@@ -621,6 +622,12 @@ Get any Cash App user's profile picture by their Cashtag.
621
622
 
622
623
  e.g., [unavatar.io/cashapp/ninja](https://unavatar.io/cashapp/ninja)
623
624
 
625
+ ### Codeforces
626
+
627
+ Get any Codeforces user's profile picture by their handle.
628
+
629
+ e.g., [unavatar.io/codeforces/tourist](https://unavatar.io/codeforces/tourist)
630
+
624
631
  ### CodePen
625
632
 
626
633
  Get any CodePen 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.49.9",
5
+ "version": "3.50.0",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -0,0 +1,33 @@
1
+ 'use strict'
2
+
3
+ const API_URL = 'https://codeforces.com/api/user.info'
4
+
5
+ const HANDLES_SEPARATOR = ';'
6
+
7
+ const DEFAULT_PHOTO_RE = /\/no-(title|avatar)\.jpg$/
8
+
9
+ const getAvatarUrl = input => `${API_URL}?handles=${encodeURIComponent(input)}`
10
+
11
+ const getAvatar = body => {
12
+ const pic = body?.result?.[0]?.titlePhoto
13
+ if (typeof pic !== 'string' || !pic) return undefined
14
+ if (DEFAULT_PHOTO_RE.test(pic)) return undefined
15
+ return pic
16
+ }
17
+
18
+ module.exports = ({ got }) =>
19
+ async function codeforces (input) {
20
+ if (input.includes(HANDLES_SEPARATOR)) return
21
+
22
+ const { body, statusCode } = await got(getAvatarUrl(input), {
23
+ responseType: 'json',
24
+ throwHttpErrors: false
25
+ })
26
+
27
+ if (statusCode >= 400) return
28
+
29
+ return getAvatar(body)
30
+ }
31
+
32
+ module.exports.getAvatarUrl = getAvatarUrl
33
+ module.exports.getAvatar = getAvatar
@@ -12,6 +12,7 @@ const providerTiers = {
12
12
  'bluesky',
13
13
  'buymeacoffee',
14
14
  'cashapp',
15
+ 'codeforces',
15
16
  'codepen',
16
17
  'cults3d',
17
18
  'cursor',
@@ -99,6 +100,7 @@ module.exports = ctx => {
99
100
  bluesky: require('./bluesky')(ctx),
100
101
  buymeacoffee: require('./buymeacoffee')(ctx),
101
102
  cashapp: require('./cashapp')(ctx),
103
+ codeforces: require('./codeforces')(ctx),
102
104
  codepen: require('./codepen')(ctx),
103
105
  cults3d: require('./cults3d')(ctx),
104
106
  cursor: require('./cursor')(ctx),