@unavatar/core 3.30.0 → 3.31.0
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.
|
|
5
|
+
"version": "3.31.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/index.js",
|
package/src/providers/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const providersBy = {
|
|
|
30
30
|
'patreon',
|
|
31
31
|
'pinterest',
|
|
32
32
|
'printables',
|
|
33
|
+
'producthunt',
|
|
33
34
|
'psnprofiles',
|
|
34
35
|
'reddit',
|
|
35
36
|
'snapchat',
|
|
@@ -85,6 +86,7 @@ module.exports = ctx => {
|
|
|
85
86
|
patreon: require('./patreon')(ctx),
|
|
86
87
|
pinterest: require('./pinterest')(ctx),
|
|
87
88
|
printables: require('./printables')(ctx),
|
|
89
|
+
producthunt: require('./producthunt')(ctx),
|
|
88
90
|
psnprofiles: require('./psnprofiles')(ctx),
|
|
89
91
|
reddit: require('./reddit')(ctx),
|
|
90
92
|
snapchat: require('./snapchat')(ctx),
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const PRODUCT_HUNT_FILES_URL = 'https://ph-files.imgix.net'
|
|
4
|
+
const PRODUCT_HUNT_PROVIDER = 'producthunt'
|
|
5
|
+
|
|
6
|
+
const getPayloadValue = (text, key) => {
|
|
7
|
+
const [, value] = text.split(`"${key}":"`)
|
|
8
|
+
return value ? value.split('"')[0].split('?')[0] : undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getScripts = $ => $('script').toArray()
|
|
12
|
+
|
|
13
|
+
const parseInput = input => {
|
|
14
|
+
const [first, ...rest] = input.split(':')
|
|
15
|
+
const type = rest.length > 0 ? first : 'user'
|
|
16
|
+
const id = rest.length > 0 ? rest.join(':') : first
|
|
17
|
+
|
|
18
|
+
if (input.startsWith('products/')) return input
|
|
19
|
+
if (type === 'product' || type === 'products') {
|
|
20
|
+
return `products/${id.replace(/^products\//, '')}`
|
|
21
|
+
}
|
|
22
|
+
if (type === 'user') return id.startsWith('@') ? id : `@${id}`
|
|
23
|
+
|
|
24
|
+
return input
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isProductInput = input => {
|
|
28
|
+
const [type, ...rest] = input.split(':')
|
|
29
|
+
const hasType = rest.length > 0
|
|
30
|
+
|
|
31
|
+
if (!hasType) return input.startsWith('products/')
|
|
32
|
+
if (type === 'product' || type === 'products') return true
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const getAvatarUrl = input => `https://www.producthunt.com/${parseInput(input)}`
|
|
37
|
+
|
|
38
|
+
const getProductHuntSlug = input => parseInput(input).replace(/^products\//, '')
|
|
39
|
+
|
|
40
|
+
const getProductHuntPayloadAvatar = $ => {
|
|
41
|
+
for (const el of getScripts($)) {
|
|
42
|
+
const text = $(el).html() || ''
|
|
43
|
+
const avatarUrl = getPayloadValue(text, 'avatarUrl')
|
|
44
|
+
|
|
45
|
+
if (avatarUrl) return avatarUrl
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getProductHuntProductAvatar = ($, input) => {
|
|
52
|
+
const slug = getProductHuntSlug(input)
|
|
53
|
+
|
|
54
|
+
for (const el of getScripts($)) {
|
|
55
|
+
const text = $(el).html() || ''
|
|
56
|
+
const slugIndex = text.indexOf(`"slug":"${slug}"`)
|
|
57
|
+
const productText =
|
|
58
|
+
slugIndex === -1
|
|
59
|
+
? text.split('"selectedBylineProduct":')[1]
|
|
60
|
+
: text.slice(slugIndex)
|
|
61
|
+
const imageUuid = productText && getPayloadValue(productText, 'logoUuid')
|
|
62
|
+
|
|
63
|
+
if (imageUuid) return `${PRODUCT_HUNT_FILES_URL}/${imageUuid}`
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return undefined
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const getProductHuntAvatar = getProductHuntPayloadAvatar
|
|
70
|
+
|
|
71
|
+
module.exports = ({ createHtmlProvider }) => {
|
|
72
|
+
const userProvider = createHtmlProvider({
|
|
73
|
+
name: PRODUCT_HUNT_PROVIDER,
|
|
74
|
+
url: getAvatarUrl,
|
|
75
|
+
getter: getProductHuntAvatar
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const provider = (input, context) => {
|
|
79
|
+
if (!isProductInput(input)) return userProvider(input, context)
|
|
80
|
+
|
|
81
|
+
return createHtmlProvider({
|
|
82
|
+
name: PRODUCT_HUNT_PROVIDER,
|
|
83
|
+
url: getAvatarUrl,
|
|
84
|
+
getter: $ => getProductHuntProductAvatar($, input)
|
|
85
|
+
})(input, context)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
provider.getUrl = getAvatarUrl
|
|
89
|
+
return provider
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports.parseInput = parseInput
|
|
93
|
+
module.exports.isProductInput = isProductInput
|
|
94
|
+
module.exports.getAvatarUrl = getAvatarUrl
|
|
95
|
+
module.exports.getProductHuntSlug = getProductHuntSlug
|
|
96
|
+
module.exports.getProductHuntPayloadAvatar = getProductHuntPayloadAvatar
|
|
97
|
+
module.exports.getProductHuntAvatar = getProductHuntAvatar
|
|
98
|
+
module.exports.getProductHuntProductAvatar = getProductHuntProductAvatar
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const parseInput = input => {
|
|
4
4
|
const [first, second] = input.split(':')
|
|
5
5
|
return {
|
|
6
6
|
type: second ? first : 'phone',
|
|
@@ -9,7 +9,7 @@ const whatsappURI = input => {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
const getAvatarUrl = input => {
|
|
12
|
-
const { type, id } =
|
|
12
|
+
const { type, id } = parseInput(input)
|
|
13
13
|
switch (type) {
|
|
14
14
|
case 'phone':
|
|
15
15
|
return `https://api.whatsapp.com/send/?phone=${id}`
|