@unavatar/core 3.7.68 → 3.7.70

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.68",
5
+ "version": "3.7.70",
6
6
  "main": "src/index.js",
7
7
  "exports": {
8
8
  ".": "./src/index.js",
@@ -15,6 +15,7 @@ const providersBy = {
15
15
  'onlyfans',
16
16
  'openstreetmap',
17
17
  'patreon',
18
+ 'printables',
18
19
  'reddit',
19
20
  'soundcloud',
20
21
  'spotify',
@@ -47,6 +48,7 @@ module.exports = ctx => {
47
48
  onlyfans: require('./onlyfans')(ctx),
48
49
  openstreetmap: require('./openstreetmap')(ctx),
49
50
  patreon: require('./patreon')(ctx),
51
+ printables: require('./printables')(ctx),
50
52
  reddit: require('./reddit')(ctx),
51
53
  soundcloud: require('./soundcloud')(ctx),
52
54
  spotify: require('./spotify')(ctx),
@@ -2,10 +2,12 @@
2
2
 
3
3
  const randomCrawlerAgent = require('../util/crawler-agent')
4
4
 
5
+ const isBlocked = $ => $('title').text().includes('Login')
6
+
5
7
  module.exports = ({ createHtmlProvider, getOgImage }) =>
6
8
  createHtmlProvider({
7
9
  name: 'instagram',
8
10
  url: input => `https://www.instagram.com/${input}`,
9
- getter: getOgImage,
11
+ getter: $ => !isBlocked($) && getOgImage($),
10
12
  htmlOpts: () => ({ headers: { 'user-agent': randomCrawlerAgent() } })
11
13
  })
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const randomCrawlerAgent = require('../util/crawler-agent')
4
+
5
+ module.exports = ({ createHtmlProvider, getOgImage }) =>
6
+ createHtmlProvider({
7
+ name: 'printables',
8
+ url: input =>
9
+ `https://www.printables.com/${
10
+ input.startsWith('@') ? input : `@${input}`
11
+ }`,
12
+ getter: getOgImage,
13
+ htmlOpts: () => ({ headers: { 'user-agent': randomCrawlerAgent() } })
14
+ })
@@ -18,9 +18,23 @@ const createEmptyProviderValueError = ({ provider, statusCode }) =>
18
18
  message: 'Empty value returned by the provider.'
19
19
  })
20
20
 
21
- const getOgImage = $ => $('meta[property="og:image"]').attr('content')
21
+
22
+ const getOgImage = $ =>
23
+ $('meta[property="og:image"]').attr('content') ||
24
+ $('meta[name="og:image"]').attr('content')
22
25
 
23
26
  module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
27
+ /**
28
+ * @param {object} opts
29
+ * @param {string} opts.name - Provider identifier used in logs and metrics.
30
+ * @param {(input: string) => string | Promise<string>} opts.url - Builds the URL to fetch for a given input.
31
+ * @param {($: cheerio.CheerioAPI) => string | false | undefined} opts.getter
32
+ * Extracts the avatar URL from the fetched HTML.
33
+ * - `string` — avatar URL found (success).
34
+ * - `undefined` — avatar not found (normal failure, no retry).
35
+ * - `false` — page is blocked; error.blocked will be set to true.
36
+ * @param {() => object} [opts.htmlOpts] - Returns extra options merged into the fetch call.
37
+ */
24
38
  const createHtmlProvider = ({ name, url, getter, htmlOpts }) => {
25
39
  const provider = async function ({ input, req = {}, res = {} }) {
26
40
  const providerUrl = await url(input)
@@ -57,8 +71,9 @@ module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
57
71
  statusCode
58
72
  })
59
73
  error.html = attempt.lastHtml
74
+ if (result === false) error.blocked = true
60
75
 
61
- log.error({ statusCode })
76
+ log.error({ statusCode, status: result === false ? 'blocked' : undefined })
62
77
 
63
78
  throw error
64
79
  }