@unavatar/core 3.71.0 → 3.71.1

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 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.71.0",
5
+ "version": "3.71.1",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -1,5 +1,12 @@
1
1
  'use strict'
2
2
 
3
+ const uniqueRandomArray = require('unique-random-array')
4
+
5
+ // Mobile user agents get an HTML page instead of the user_json payload.
6
+ const randomDesktopUserAgent = uniqueRandomArray(
7
+ require('top-user-agents/desktop')
8
+ )
9
+
3
10
  const PORTRAIT_URL = 'https://himg.bdimg.com/sys/portrait/item'
4
11
 
5
12
  const getAvatarUrl = input =>
@@ -17,7 +24,8 @@ module.exports = ({ got }) =>
17
24
  // Unknown users respond with an empty body, which is not valid JSON.
18
25
  const { body, statusCode } = await got(getAvatarUrl(input), {
19
26
  responseType: 'text',
20
- throwHttpErrors: false
27
+ throwHttpErrors: false,
28
+ headers: { 'user-agent': randomDesktopUserAgent() }
21
29
  })
22
30
 
23
31
  if (statusCode >= 400 || !body) return
@@ -1,5 +1,12 @@
1
1
  'use strict'
2
2
 
3
+ const uniqueRandomArray = require('unique-random-array')
4
+
5
+ // Mobile user agents get a 403 from the members API.
6
+ const randomDesktopUserAgent = uniqueRandomArray(
7
+ require('top-user-agents/desktop')
8
+ )
9
+
3
10
  const API_URL = 'https://www.zhihu.com/api/v4/members'
4
11
 
5
12
  const getAvatarUrl = input =>
@@ -16,7 +23,8 @@ module.exports = ({ got }) =>
16
23
  async function zhihu (input) {
17
24
  const { body, statusCode } = await got(getAvatarUrl(input), {
18
25
  responseType: 'json',
19
- throwHttpErrors: false
26
+ throwHttpErrors: false,
27
+ headers: { 'user-agent': randomDesktopUserAgent() }
20
28
  })
21
29
 
22
30
  if (statusCode >= 400) return