@unavatar/core 3.7.74 → 3.7.75

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.7.74",
5
+ "version": "3.7.75",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -1,11 +1,8 @@
1
1
  'use strict'
2
2
 
3
- const randomCrawlerAgent = require('../util/crawler-agent')
4
-
5
3
  module.exports = ({ createHtmlProvider, getOgImage }) =>
6
4
  createHtmlProvider({
7
5
  name: 'instagram',
8
6
  url: input => `https://www.instagram.com/${input}`,
9
- getter: getOgImage,
10
- htmlOpts: () => ({ headers: { 'user-agent': randomCrawlerAgent() } })
7
+ getter: getOgImage
11
8
  })
@@ -1,7 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const randomCrawlerAgent = require('../util/crawler-agent')
4
-
5
3
  module.exports = ({ createHtmlProvider, getOgImage }) =>
6
4
  createHtmlProvider({
7
5
  name: 'printables',
@@ -9,6 +7,5 @@ module.exports = ({ createHtmlProvider, getOgImage }) =>
9
7
  `https://www.printables.com/${
10
8
  input.startsWith('@') ? input : `@${input}`
11
9
  }`,
12
- getter: getOgImage,
13
- htmlOpts: () => ({ headers: { 'user-agent': randomCrawlerAgent() } })
10
+ getter: getOgImage
14
11
  })
@@ -2,8 +2,6 @@
2
2
 
3
3
  const { $jsonld } = require('@metascraper/helpers')
4
4
 
5
- const randomCrawlerAgent = require('../util/crawler-agent')
6
-
7
5
  const toHighResolution = url => {
8
6
  if (url?.endsWith('_200x200.jpg')) {
9
7
  return url.replace('_200x200.jpg', '_400x400.jpg')
@@ -16,15 +14,15 @@ const toHighResolution = url => {
16
14
 
17
15
  const getProfileImage = $ =>
18
16
  toHighResolution(
19
- $jsonld('mainEntity.image.contentUrl')($) || $('meta[property="og:image"]').attr('content')
17
+ $jsonld('mainEntity.image.contentUrl')($) ||
18
+ $('meta[property="og:image"]').attr('content')
20
19
  )
21
20
 
22
21
  const factory = ({ createHtmlProvider }) =>
23
22
  createHtmlProvider({
24
23
  name: 'x',
25
24
  url: input => `https://x.com/${input}`,
26
- getter: getProfileImage,
27
- htmlOpts: () => ({ headers: { 'user-agent': randomCrawlerAgent() } })
25
+ getter: getProfileImage
28
26
  })
29
27
 
30
28
  factory.getProfileImage = getProfileImage
@@ -2,7 +2,4 @@
2
2
 
3
3
  const uniqueRandomArray = require('unique-random-array')
4
4
 
5
- // TODO: update top-crawler-agents to don't make necessary to filter.
6
- module.exports = uniqueRandomArray(
7
- require('top-crawler-agents').filter(agent => agent.startsWith('Slackbot'))
8
- )
5
+ module.exports = uniqueRandomArray(require('top-crawler-agents'))
@@ -4,6 +4,7 @@ const { normalizeUrl } = require('@metascraper/helpers')
4
4
  const debug = require('debug-logfmt')('html-provider')
5
5
  const isAntibot = require('is-antibot')
6
6
 
7
+ const randomCrawlerAgent = require('./crawler-agent')
7
8
  const httpStatus = require('./http-status')
8
9
  const ExtendableError = require('./error')
9
10
 
@@ -43,7 +44,15 @@ module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
43
44
  const context = { provider: name, input, providerUrl }
44
45
 
45
46
  const attempt = async gotOpts => {
46
- const defaultOpts = { ...htmlOpts?.(), timeout: PROXY_TIMEOUT }
47
+ const providerOpts = htmlOpts?.() ?? {}
48
+ const defaultOpts = {
49
+ ...providerOpts,
50
+ headers: {
51
+ 'user-agent': randomCrawlerAgent(),
52
+ ...providerOpts.headers
53
+ },
54
+ timeout: PROXY_TIMEOUT
55
+ }
47
56
  const fetchOpts = gotOpts ? { ...defaultOpts, ...gotOpts } : defaultOpts
48
57
  const tier = fetchOpts.tier ?? 'origin'
49
58