-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (74 loc) · 2.4 KB
/
index.js
File metadata and controls
86 lines (74 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict'
const DEFAULTS = require('./constant')
module.exports = ({
constants: userConstants,
redis,
onFetchHTML,
userAgent
} = {}) => {
const constants = { ...DEFAULTS, ...userConstants }
if (userConstants?.REQUEST_TIMEOUT && !userConstants?.PROXY_TIMEOUT) {
constants.PROXY_TIMEOUT = Math.floor(constants.REQUEST_TIMEOUT * (1 / 3))
}
if (userConstants?.REQUEST_TIMEOUT && !userConstants?.DNS_TIMEOUT) {
constants.DNS_TIMEOUT = Math.floor(constants.REQUEST_TIMEOUT * (1 / 5))
}
const { createMultiCache, createRedisCache } = require('./util/keyv')({
...constants,
redis
})
const cache = require('./util/cache')({ createMultiCache, createRedisCache })
const cacheableLookup = require('./util/cacheable-lookup')({
...constants,
cache: cache.dnsCache
})
const isReservedIp = require('./util/is-reserved-ip')({ cacheableLookup })
const got = require('./util/got')({ cacheableLookup })
const reachableUrl = require('./util/reachable-url')({
got,
pingCache: cache.pingCache
})
const createBrowser = require('./util/browserless')(constants)
const getHTML = require('./util/html-get')({ createBrowser, got })
const { createHtmlProvider, getOgImage, NOT_FOUND } =
require('./util/html-provider')({
...constants,
getHTML,
onFetchHTML,
userAgent
})
const providerCtx = {
constants,
createHtmlProvider,
getOgImage,
NOT_FOUND,
got,
isReservedIp,
githubSearchCache: cache.githubSearchCache,
itunesSearchCache: cache.itunesSearchCache
}
const { providers, providersBy } = require('./providers')(providerCtx)
const { auto, getInputType, getAvatar } = require('./avatar/auto')({
constants,
providers,
providersBy,
reachableUrl
})
const unavatar = input => auto(getInputType(input))(input, {})
Object.keys(providers).forEach(name => {
unavatar[name] = input => getAvatar(providers[name], name, input, {})
})
const createTypedAutoResolver = inputType => input =>
auto(inputType)(input, {})
unavatar.email = createTypedAutoResolver('email')
unavatar.domain = createTypedAutoResolver('domain')
unavatar.auto = auto
unavatar.getInputType = getInputType
unavatar.getAvatar = getAvatar
unavatar.providers = providers
unavatar.providersBy = providersBy
unavatar.reachableUrl = reachableUrl
unavatar.got = got
unavatar.createBrowser = createBrowser
return unavatar
}