@unavatar/core 3.25.4 → 3.25.6
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 +1 -2
- package/package.json +2 -1
- package/src/index.js +10 -3
- package/src/util/html-provider.js +10 -6
package/README.md
CHANGED
|
@@ -319,8 +319,7 @@ If explicit type is not provided, it defaults to `id`.
|
|
|
319
319
|
|
|
320
320
|
Available inputs:
|
|
321
321
|
|
|
322
|
-
- `id` (default): [unavatar.io/apple-store/id:529479190](https://unavatar.io/apple-store/id:529479190)
|
|
323
|
-
- `id`: [unavatar.io/apple-store/id:6474323148@es](https://unavatar.io/apple-store/id:6474323148@es)
|
|
322
|
+
- `id` (default): [unavatar.io/apple-store/id:529479190](https://unavatar.io/apple-store/id:529479190) or [unavatar.io/apple-store/id:6474323148@es](https://unavatar.io/apple-store/id:6474323148@es)
|
|
324
323
|
- `name`: [unavatar.io/apple-store/name:pokemon%20go](https://unavatar.io/apple-store/name:pokemon%20go)
|
|
325
324
|
|
|
326
325
|
### Behance
|
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.25.
|
|
5
|
+
"version": "3.25.6",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
|
@@ -206,6 +206,7 @@
|
|
|
206
206
|
},
|
|
207
207
|
"nano-staged": {
|
|
208
208
|
"*.js": [
|
|
209
|
+
"npx -y @kikobeats/prettier-standard",
|
|
209
210
|
"standard --fix"
|
|
210
211
|
],
|
|
211
212
|
"package.json": [
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
const DEFAULTS = require('./constant')
|
|
4
4
|
|
|
5
|
-
module.exports = ({
|
|
5
|
+
module.exports = ({
|
|
6
|
+
constants: userConstants,
|
|
7
|
+
redis,
|
|
8
|
+
onFetchHTML,
|
|
9
|
+
userAgent
|
|
10
|
+
} = {}) => {
|
|
6
11
|
const constants = { ...DEFAULTS, ...userConstants }
|
|
7
12
|
|
|
8
13
|
if (userConstants?.REQUEST_TIMEOUT && !userConstants?.PROXY_TIMEOUT) {
|
|
@@ -33,7 +38,8 @@ module.exports = ({ constants: userConstants, redis, onFetchHTML } = {}) => {
|
|
|
33
38
|
require('./util/html-provider')({
|
|
34
39
|
...constants,
|
|
35
40
|
getHTML,
|
|
36
|
-
onFetchHTML
|
|
41
|
+
onFetchHTML,
|
|
42
|
+
userAgent
|
|
37
43
|
})
|
|
38
44
|
|
|
39
45
|
const providerCtx = {
|
|
@@ -61,7 +67,8 @@ module.exports = ({ constants: userConstants, redis, onFetchHTML } = {}) => {
|
|
|
61
67
|
unavatar[name] = input => getAvatar(providers[name], name, input, {})
|
|
62
68
|
})
|
|
63
69
|
|
|
64
|
-
const createTypedAutoResolver = inputType => input =>
|
|
70
|
+
const createTypedAutoResolver = inputType => input =>
|
|
71
|
+
auto(inputType)(input, {})
|
|
65
72
|
|
|
66
73
|
unavatar.email = createTypedAutoResolver('email')
|
|
67
74
|
unavatar.domain = createTypedAutoResolver('domain')
|
|
@@ -4,7 +4,6 @@ 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')
|
|
8
7
|
const getOgImage = require('./get-og-image')
|
|
9
8
|
const httpStatus = require('./http-status')
|
|
10
9
|
const ExtendableError = require('./error')
|
|
@@ -34,7 +33,12 @@ const createErrorCause = ({ html, headers, statusCode }) => ({
|
|
|
34
33
|
statusCode
|
|
35
34
|
})
|
|
36
35
|
|
|
37
|
-
module.exports = ({
|
|
36
|
+
module.exports = ({
|
|
37
|
+
PROXY_TIMEOUT,
|
|
38
|
+
getHTML,
|
|
39
|
+
onFetchHTML,
|
|
40
|
+
userAgent = require('./crawler-agent')
|
|
41
|
+
}) => {
|
|
38
42
|
/**
|
|
39
43
|
* @param {object} opts
|
|
40
44
|
* @param {string} opts.name - Provider identifier used in logs and metrics.
|
|
@@ -55,13 +59,13 @@ module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
|
|
|
55
59
|
const defaultOpts = {
|
|
56
60
|
...providerOpts,
|
|
57
61
|
headers: {
|
|
58
|
-
'user-agent':
|
|
62
|
+
'user-agent': userAgent({ provider: name }),
|
|
59
63
|
...providerOpts.headers
|
|
60
64
|
},
|
|
61
65
|
timeout: PROXY_TIMEOUT
|
|
62
66
|
}
|
|
63
67
|
const fetchOpts = { ...defaultOpts, ...gotOpts }
|
|
64
|
-
const
|
|
68
|
+
const resolvedUserAgent = fetchOpts.headers['user-agent']
|
|
65
69
|
const tier = fetchOpts.tier ?? 'origin'
|
|
66
70
|
|
|
67
71
|
const log = debug.duration({ provider: name, input, providerUrl, tier })
|
|
@@ -151,7 +155,7 @@ module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
|
|
|
151
155
|
statusCode,
|
|
152
156
|
status: 'blocked',
|
|
153
157
|
antibot: antibotProvider ?? undefined,
|
|
154
|
-
userAgent
|
|
158
|
+
userAgent: resolvedUserAgent
|
|
155
159
|
})
|
|
156
160
|
|
|
157
161
|
throw error
|
|
@@ -167,7 +171,7 @@ module.exports = ({ PROXY_TIMEOUT, getHTML, onFetchHTML }) => {
|
|
|
167
171
|
log.error({
|
|
168
172
|
statusCode,
|
|
169
173
|
antibot: antibotProvider ?? undefined,
|
|
170
|
-
userAgent
|
|
174
|
+
userAgent: resolvedUserAgent
|
|
171
175
|
})
|
|
172
176
|
|
|
173
177
|
throw error
|