@ecency/render-helper 2.3.17 → 2.4.1
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/LICENSE +1 -1
- package/README.md +171 -17
- package/dist/browser/index.d.ts +32 -0
- package/dist/browser/index.js +1556 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/node/index.cjs +1575 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.mjs +1559 -0
- package/dist/node/index.mjs.map +1 -0
- package/package.json +49 -47
- package/lib/cache.d.ts +0 -3
- package/lib/cache.js +0 -21
- package/lib/cache.js.map +0 -1
- package/lib/catch-post-image.d.ts +0 -2
- package/lib/catch-post-image.js +0 -76
- package/lib/catch-post-image.js.map +0 -1
- package/lib/consts/allowed-attributes.const.d.ts +0 -2
- package/lib/consts/allowed-attributes.const.js +0 -71
- package/lib/consts/allowed-attributes.const.js.map +0 -1
- package/lib/consts/dom-parser.const.d.ts +0 -2
- package/lib/consts/dom-parser.const.js +0 -12
- package/lib/consts/dom-parser.const.js.map +0 -1
- package/lib/consts/index.d.ts +0 -5
- package/lib/consts/index.js +0 -22
- package/lib/consts/index.js.map +0 -1
- package/lib/consts/regexes.const.d.ts +0 -44
- package/lib/consts/regexes.const.js +0 -49
- package/lib/consts/regexes.const.js.map +0 -1
- package/lib/consts/section-list.const.d.ts +0 -1
- package/lib/consts/section-list.const.js +0 -24
- package/lib/consts/section-list.const.js.map +0 -1
- package/lib/consts/white-list.const.d.ts +0 -2
- package/lib/consts/white-list.const.js +0 -37
- package/lib/consts/white-list.const.js.map +0 -1
- package/lib/helper.d.ts +0 -6
- package/lib/helper.js +0 -72
- package/lib/helper.js.map +0 -1
- package/lib/index.d.ts +0 -8
- package/lib/index.js +0 -19
- package/lib/index.js.map +0 -1
- package/lib/markdown-2-html.d.ts +0 -2
- package/lib/markdown-2-html.js +0 -25
- package/lib/markdown-2-html.js.map +0 -1
- package/lib/methods/a.method.d.ts +0 -1
- package/lib/methods/a.method.js +0 -647
- package/lib/methods/a.method.js.map +0 -1
- package/lib/methods/clean-reply.method.d.ts +0 -1
- package/lib/methods/clean-reply.method.js +0 -37
- package/lib/methods/clean-reply.method.js.map +0 -1
- package/lib/methods/get-inner-html.method.d.ts +0 -1
- package/lib/methods/get-inner-html.method.js +0 -16
- package/lib/methods/get-inner-html.method.js.map +0 -1
- package/lib/methods/iframe.method.d.ts +0 -1
- package/lib/methods/iframe.method.js +0 -159
- package/lib/methods/iframe.method.js.map +0 -1
- package/lib/methods/img.method.d.ts +0 -4
- package/lib/methods/img.method.js +0 -50
- package/lib/methods/img.method.js.map +0 -1
- package/lib/methods/index.d.ts +0 -7
- package/lib/methods/index.js +0 -24
- package/lib/methods/index.js.map +0 -1
- package/lib/methods/linkify.method.d.ts +0 -1
- package/lib/methods/linkify.method.js +0 -56
- package/lib/methods/linkify.method.js.map +0 -1
- package/lib/methods/markdown-to-html.method.d.ts +0 -1
- package/lib/methods/markdown-to-html.method.js +0 -98
- package/lib/methods/markdown-to-html.method.js.map +0 -1
- package/lib/methods/noop.method.d.ts +0 -1
- package/lib/methods/noop.method.js +0 -6
- package/lib/methods/noop.method.js.map +0 -1
- package/lib/methods/p.method.d.ts +0 -1
- package/lib/methods/p.method.js +0 -11
- package/lib/methods/p.method.js.map +0 -1
- package/lib/methods/remove-child-nodes.method.d.ts +0 -1
- package/lib/methods/remove-child-nodes.method.js +0 -10
- package/lib/methods/remove-child-nodes.method.js.map +0 -1
- package/lib/methods/sanitize-html.method.d.ts +0 -1
- package/lib/methods/sanitize-html.method.js +0 -42
- package/lib/methods/sanitize-html.method.js.map +0 -1
- package/lib/methods/text.method.d.ts +0 -1
- package/lib/methods/text.method.js +0 -69
- package/lib/methods/text.method.js.map +0 -1
- package/lib/methods/traverse.method.d.ts +0 -3
- package/lib/methods/traverse.method.js +0 -38
- package/lib/methods/traverse.method.js.map +0 -1
- package/lib/post-body-summary.d.ts +0 -2
- package/lib/post-body-summary.js +0 -123
- package/lib/post-body-summary.js.map +0 -1
- package/lib/proxify-image-src.d.ts +0 -5
- package/lib/proxify-image-src.js +0 -86
- package/lib/proxify-image-src.js.map +0 -1
- package/lib/render-helper.js +0 -1
- package/lib/types/entry.interface.d.ts +0 -7
- package/lib/types/entry.interface.js +0 -3
- package/lib/types/entry.interface.js.map +0 -1
- package/lib/types/index.d.ts +0 -2
- package/lib/types/index.js +0 -19
- package/lib/types/index.js.map +0 -1
- package/lib/types/xss-white-list.interface.d.ts +0 -6
- package/lib/types/xss-white-list.interface.js +0 -3
- package/lib/types/xss-white-list.interface.js.map +0 -1
- package/src/cache.ts +0 -15
- package/src/catch-post-image.spec.ts +0 -144
- package/src/catch-post-image.ts +0 -78
- package/src/consts/allowed-attributes.const.ts +0 -69
- package/src/consts/dom-parser.const.ts +0 -6
- package/src/consts/index.ts +0 -5
- package/src/consts/regexes.const.ts +0 -46
- package/src/consts/section-list.const.ts +0 -20
- package/src/consts/white-list.const.ts +0 -33
- package/src/external-types/multihashes.d.ts +0 -3
- package/src/helper.spec.ts +0 -16
- package/src/helper.ts +0 -77
- package/src/index.ts +0 -18
- package/src/markdown-2-html.spec.ts +0 -1251
- package/src/markdown-2-html.ts +0 -25
- package/src/methods/a.method.ts +0 -791
- package/src/methods/clean-reply.method.ts +0 -32
- package/src/methods/get-inner-html.method.ts +0 -11
- package/src/methods/iframe.method.ts +0 -176
- package/src/methods/img.method.ts +0 -62
- package/src/methods/index.ts +0 -7
- package/src/methods/linkify.method.ts +0 -61
- package/src/methods/markdown-to-html.method.ts +0 -104
- package/src/methods/noop.method.ts +0 -1
- package/src/methods/p.method.ts +0 -6
- package/src/methods/remove-child-nodes.method.ts +0 -5
- package/src/methods/sanitize-html.method.ts +0 -32
- package/src/methods/text.method.ts +0 -77
- package/src/methods/traverse.method.ts +0 -33
- package/src/post-body-summary.spec.ts +0 -150
- package/src/post-body-summary.ts +0 -130
- package/src/proxify-image-src.spec.ts +0 -76
- package/src/proxify-image-src.ts +0 -77
- package/src/sanitize-html.spec.ts +0 -15
- package/src/test/data/index.ts +0 -12
- package/src/test/data/json/muratkbesiroglu____sci-fi-novel-underground-city-part-13.json +0 -2120
- package/src/test/data/json/steemitboard____steemitboard-notify-dunsky-20181210t153450000z.json +0 -47
- package/src/test/data/legacy/10.json +0 -5
- package/src/test/data/legacy/20.json +0 -5
- package/src/test/data/legacy/21.json +0 -5
- package/src/test/data/legacy/2112524.json +0 -5
- package/src/test/data/legacy/22.json +0 -5
- package/src/test/data/legacy/23.json +0 -5
- package/src/test/data/legacy/24.json +0 -5
- package/src/test/data/legacy/25.json +0 -5
- package/src/test/data/legacy/26.json +0 -5
- package/src/test/data/legacy/27.JSON +0 -5
- package/src/test/data/legacy/28.json +0 -5
- package/src/test/data/legacy/29.json +0 -5
- package/src/test/data/legacy/31.json +0 -5
- package/src/test/snaps.json +0 -8
- package/src/types/entry.interface.ts +0 -7
- package/src/types/index.ts +0 -2
- package/src/types/xss-white-list.interface.ts +0 -7
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { getPostBodySummary } from './post-body-summary'
|
|
2
|
-
|
|
3
|
-
describe('postBodySummary', () => {
|
|
4
|
-
it('1- Should return empty string', () => {
|
|
5
|
-
const input = {
|
|
6
|
-
author: 'foo81',
|
|
7
|
-
permlink: 'bar81',
|
|
8
|
-
last_update: '2019-05-10T09:15:21',
|
|
9
|
-
body: ''
|
|
10
|
-
}
|
|
11
|
-
const expected = ''
|
|
12
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('2- Should remove html tags', () => {
|
|
16
|
-
const input = {
|
|
17
|
-
author: 'foo82',
|
|
18
|
-
permlink: 'bar82',
|
|
19
|
-
last_update: '2019-05-10T09:15:21',
|
|
20
|
-
body: '<center>Lorem Ipsum Dolor</center>'
|
|
21
|
-
}
|
|
22
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
23
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('3- Should remove new lines', () => {
|
|
27
|
-
const input = {
|
|
28
|
-
author: 'foo83',
|
|
29
|
-
permlink: 'bar83',
|
|
30
|
-
last_update: '2019-05-10T09:15:21',
|
|
31
|
-
body: 'Lorem \n Ipsum \n Dolor'
|
|
32
|
-
}
|
|
33
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
34
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('4- Should trim', () => {
|
|
38
|
-
const input = {
|
|
39
|
-
author: 'foo84',
|
|
40
|
-
permlink: 'bar84',
|
|
41
|
-
last_update: '2019-05-10T09:15:21',
|
|
42
|
-
body: ' Lorem Ipsum Dolor '
|
|
43
|
-
}
|
|
44
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
45
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('5- Should remove urls', () => {
|
|
49
|
-
const input = {
|
|
50
|
-
author: 'foo85',
|
|
51
|
-
permlink: 'bar85',
|
|
52
|
-
last_update: '2019-05-10T09:15:21',
|
|
53
|
-
body: 'Lorem http://lorem.com Ipsum Dolor https://ipsum.com'
|
|
54
|
-
}
|
|
55
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
56
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('6- Should remove white spaces between words', () => {
|
|
60
|
-
const input = {
|
|
61
|
-
author: 'foo86',
|
|
62
|
-
permlink: 'bar86',
|
|
63
|
-
last_update: '2019-05-10T09:15:21',
|
|
64
|
-
body: ' Lorem Ipsum Dolor '
|
|
65
|
-
}
|
|
66
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
67
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('7- Should limit to 20', () => {
|
|
71
|
-
const input = {
|
|
72
|
-
author: 'foo87',
|
|
73
|
-
permlink: 'bar87',
|
|
74
|
-
last_update: '2019-05-10T09:15:21',
|
|
75
|
-
body: 'lorem ipsum dolor sit amet'
|
|
76
|
-
}
|
|
77
|
-
const expected = 'lorem ipsum dolor sit'
|
|
78
|
-
expect(getPostBodySummary(input, 20)).toBe(expected)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('8- Test with long markdown', () => {
|
|
82
|
-
const input = {
|
|
83
|
-
author: 'foo88',
|
|
84
|
-
permlink: 'bar88',
|
|
85
|
-
last_update: '2019-05-10T09:15:21',
|
|
86
|
-
body: `https://youtu.be/DII2VTXDP7A
|
|
87
|
-
In this post, we want to bring you up to speed on what is happening inside Steemit, as well as give you our perspective on the successes (and failures) of the past year, let you know what we see as our mission going forward, and provide some insight into what we have planned.
|
|
88
|
-
<h1>Steemit’s Vision and Mission</h1>
|
|
89
|
-
Through our vision of **empowering entrepreneurs to tokenize the internet**, our primary roles in the Steem ecosystem are providing the community with software enhancements to the Steem blockchain, modular framework applications made up of components that can be leveraged by application developers and inspiration through these platforms to entrepreneurial end-users. We believe we must build in ways that create as many opportunities — and catalyze as many amazing Steem-based entrepreneurs and communities — as possible.`
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const expected = 'In this post, we want to bring you up to speed on what is happening inside Steemit, as well as give you our perspective on the successes (and failures) of the past year, let you know what we see as our'
|
|
93
|
-
expect(getPostBodySummary(input, 200)).toBe(expected)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('9- Test with long markdown', () => {
|
|
97
|
-
const input = {
|
|
98
|
-
author: 'foo89',
|
|
99
|
-
permlink: 'bar89',
|
|
100
|
-
last_update: '2019-05-10T09:15:21',
|
|
101
|
-
body: `<html>
|
|
102
|
-
<center><a href='https://d.tube/#!/v/surfermarly/x2zm8s26'><img src='https://images.ecency.com/DQmdxVxFgLu8PT1TchgQUHtd7LGvKtF5u1DbHmDDKALiwxi/dreamsd1.jpg'></a></center><hr>
|
|
103
|
-
<p><b>Everybody has a dream. Most of the time it takes us a while to turn these great wishes into reality, especially because they usually come with a bigger price tag.</b></p>
|
|
104
|
-
<p>Now thanks to Steem some of us will be able to cut corners in order to achieve their goals more quickly. The additional income can be a game changer to many players.</p>
|
|
105
|
-
<p>My Steem earnings enabled me to buy a piece of land where I'll build my first own house. Writing down these words still seems a bit unreal to me, since I didn't believe to come to that point so quickly.</p>
|
|
106
|
-
<h3>Click on the above image or <a href='https://d.tube/#!/v/surfermarly/x2zm8s26'>HERE ▶️</a> to watch my video statement.</h3>
|
|
107
|
-
<p>Without hard work and dedication as well as the great support from the community this wouldn't have been possible. Also the timing was brilliant, I joined in the earlier stages.</p>
|
|
108
|
-
<p><b>I'm both grateful and proud.</b></p>
|
|
109
|
-
<p>Many people supported me along the way, some tried to tear me down. I'm glad I only stayed with those who pushed me, they have a large stake in my success story.</p></html>`
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const expected = 'Everybody has a dream. Most of the time it takes us a while to turn these great wishes into reality, especially because they usually come with a bigger price tag. Now thanks to Steem some of us will be'
|
|
113
|
-
expect(getPostBodySummary(input, 200)).toBe(expected)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('10- Test with long markdown', () => {
|
|
117
|
-
const input = {
|
|
118
|
-
author: 'foo90',
|
|
119
|
-
permlink: 'bar90',
|
|
120
|
-
last_update: '2019-05-10T09:15:21',
|
|
121
|
-
body: `<center><a href='https://d.tube/#!/v/marpemusic/gi5e9yrl'><img src='https://ipfs.io/ipfs/QmYK5yzDHyoDVQQ5xgV4RLzcZz5Qy95Hz1n6qbEusJGHYB'></a></center><hr>
|
|
122
|
-

|
|
123
|
-
###### Hey Dtube!
|
|
124
|
-
###### Hey Steemian
|
|
125
|
-
###### It's your boy marpe @marpemusic. I greet you from my stable, Ibadan Nigeria.
|
|
126
|
-
**There's excitement in the air! The epoch making STEEMIB (that is, STEEMIT IBADAN) meet up is around the corner!! Where would you rather be on the 24th of February 2018? You don't want to miss this peeps.**
|
|
127
|
-

|
|
128
|
-
### Boooommm!!!
|
|
129
|
-
I'm giving Three DTUBE & STEEMIT BRANDED TEES to three people for free. Yes, for free. *E fit be you ooo!*
|
|
130
|
-
So, how can you qualify to get one?`
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const expected = 'Hey Dtube! Hey Steemian It\'s your boy marpe @marpemusic. I greet you from my stable, Ibadan Nigeria. There\'s excitement in the air! The epoch making STEEMIB (that is, STEEMIT IBADAN) meet up is around'
|
|
134
|
-
|
|
135
|
-
expect(getPostBodySummary(input, 200)).toBe(expected)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
it('11- Test with not obj param', () => {
|
|
139
|
-
const input = '<center>Lorem Ipsum Dolor</center>'
|
|
140
|
-
const expected = 'Lorem Ipsum Dolor'
|
|
141
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
it('12- Test entity parsing', () => {
|
|
146
|
-
const input = 'http://lorem.com Lorem < Ipsum & Dolor € '
|
|
147
|
-
const expected = 'Lorem < Ipsum & Dolor €'
|
|
148
|
-
expect(getPostBodySummary(input)).toBe(expected)
|
|
149
|
-
})
|
|
150
|
-
})
|
package/src/post-body-summary.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import he from 'he'
|
|
2
|
-
import { makeEntryCacheKey } from './helper'
|
|
3
|
-
import { cacheGet, cacheSet } from './cache'
|
|
4
|
-
import { Entry } from './types'
|
|
5
|
-
import { cleanReply } from './methods'
|
|
6
|
-
import { ENTITY_REGEX } from './consts'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { Remarkable } = require('remarkable')
|
|
10
|
-
const { linkify } = require('remarkable/linkify')
|
|
11
|
-
|
|
12
|
-
const joint = (arr: string[], limit = 200) => {
|
|
13
|
-
let result = '';
|
|
14
|
-
if (arr) {
|
|
15
|
-
for (let i = 0; i < arr.length; i++) {
|
|
16
|
-
// join array with space separator
|
|
17
|
-
if (result) {
|
|
18
|
-
result += " ";
|
|
19
|
-
}
|
|
20
|
-
// break with length reaches limit
|
|
21
|
-
if (result.length > limit) {
|
|
22
|
-
break;
|
|
23
|
-
} else {
|
|
24
|
-
// make sure last join doesn't break the limit too much
|
|
25
|
-
if ((result + arr[i]).length < limit + 10) {
|
|
26
|
-
result += arr[i];
|
|
27
|
-
} else {
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result.trim();
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function postBodySummary(entryBody: string, length?: number, platform:'ios'|'android'|'web' = 'web'): string {
|
|
37
|
-
if (!entryBody) {
|
|
38
|
-
return ''
|
|
39
|
-
}
|
|
40
|
-
entryBody = cleanReply(entryBody)
|
|
41
|
-
|
|
42
|
-
const mdd = new Remarkable({
|
|
43
|
-
html: true,
|
|
44
|
-
breaks: true,
|
|
45
|
-
typographer: false,
|
|
46
|
-
}).use(linkify)
|
|
47
|
-
mdd.core.ruler.enable([
|
|
48
|
-
'abbr'
|
|
49
|
-
]);
|
|
50
|
-
mdd.block.ruler.enable([
|
|
51
|
-
'footnote',
|
|
52
|
-
'deflist'
|
|
53
|
-
]);
|
|
54
|
-
mdd.inline.ruler.enable([
|
|
55
|
-
'footnote_inline',
|
|
56
|
-
'ins',
|
|
57
|
-
'mark',
|
|
58
|
-
'sub',
|
|
59
|
-
'sup'
|
|
60
|
-
]);
|
|
61
|
-
|
|
62
|
-
//encrypt entities
|
|
63
|
-
const entities = entryBody.match(ENTITY_REGEX);
|
|
64
|
-
const encEntities:string[] = [];
|
|
65
|
-
if(entities && platform !== 'web'){
|
|
66
|
-
entities.forEach((entity)=>{
|
|
67
|
-
var CryptoJS = require("react-native-crypto-js");
|
|
68
|
-
const encData = CryptoJS.AES.encrypt(entity, 'key').toString();
|
|
69
|
-
let encyptedEntity = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encData));
|
|
70
|
-
encEntities.push(encyptedEntity);
|
|
71
|
-
entryBody = entryBody.replace(entity, encyptedEntity);
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Convert markdown to html
|
|
76
|
-
let text = '';
|
|
77
|
-
try {
|
|
78
|
-
text = mdd.render(entryBody)
|
|
79
|
-
} catch (err) {
|
|
80
|
-
console.log(err)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//decrypt and put back entiteis
|
|
85
|
-
if(platform !== 'web'){
|
|
86
|
-
encEntities.forEach((encEntity)=>{
|
|
87
|
-
var CryptoJS = require("react-native-crypto-js");
|
|
88
|
-
let decData = CryptoJS.enc.Base64.parse(encEntity).toString(CryptoJS.enc.Utf8);
|
|
89
|
-
let entity = CryptoJS.AES.decrypt(decData, 'key').toString(CryptoJS.enc.Utf8);
|
|
90
|
-
text = text.replace(encEntity, entity);
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
text = text
|
|
96
|
-
.replace(/(<([^>]+)>)/gi, '') // Remove html tags
|
|
97
|
-
.replace(/\r?\n|\r/g, ' ') // Remove new lines
|
|
98
|
-
.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '') // Remove urls
|
|
99
|
-
.trim()
|
|
100
|
-
.replace(/ +(?= )/g, '') // Remove all multiple spaces
|
|
101
|
-
|
|
102
|
-
if (length) {
|
|
103
|
-
// Truncate
|
|
104
|
-
text = joint(text.split(' '), length)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (text) {
|
|
108
|
-
text = he.decode(text) // decode html entities
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return text
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function getPostBodySummary(obj: Entry | string, length?: number, platform?:'ios'|'android'|'web'): any {
|
|
115
|
-
if (typeof obj === 'string') {
|
|
116
|
-
return postBodySummary(obj as string, length, platform)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const key = `${makeEntryCacheKey(obj)}-sum-${length}`
|
|
120
|
-
|
|
121
|
-
const item = cacheGet(key)
|
|
122
|
-
if (item) {
|
|
123
|
-
return item
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const res = postBodySummary(obj.body, length, platform)
|
|
127
|
-
cacheSet(key, res)
|
|
128
|
-
|
|
129
|
-
return res
|
|
130
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { proxifyImageSrc, setProxyBase, getLatestUrl, extractPHash } from './proxify-image-src'
|
|
2
|
-
|
|
3
|
-
describe('getLatestUrl', () => {
|
|
4
|
-
it('1- should get the latest url', () => {
|
|
5
|
-
const input = 'https://i.imgur.com/muESb0B.png'
|
|
6
|
-
|
|
7
|
-
expect(getLatestUrl(input)).toBe('https://i.imgur.com/muESb0B.png')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('2- should get the latest url', () => {
|
|
11
|
-
const input = 'https://images.ecency.com/0x0/https://i.imgur.com/muESb0B.png'
|
|
12
|
-
|
|
13
|
-
expect(getLatestUrl(input)).toBe('https://i.imgur.com/muESb0B.png')
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('3- should get the latest url', () => {
|
|
17
|
-
const input = 'https://images.ecency.com/0x0/https://images.hive.io/0x0/https://i.imgur.com/muESb0B.png'
|
|
18
|
-
|
|
19
|
-
expect(getLatestUrl(input)).toBe('https://i.imgur.com/muESb0B.png')
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
describe('extractPHash', () => {
|
|
24
|
-
it('1- should extract hash', () => {
|
|
25
|
-
const input = 'https://images.ecency.com/p/RGgukq5E6HBNvuPpuJoWwfXPpi5ckcLESTB3nmmnMt8YnPwgHbJegFaUzokkErqT8JVe4zPL7GD3gy6aaZQERs3MF5KAGJQ1AL4MmhLWfmceyk6XXSqWaECh1YXC7aV.png?format=match&mode=fit'
|
|
26
|
-
|
|
27
|
-
expect(extractPHash(input)).toBe('RGgukq5E6HBNvuPpuJoWwfXPpi5ckcLESTB3nmmnMt8YnPwgHbJegFaUzokkErqT8JVe4zPL7GD3gy6aaZQERs3MF5KAGJQ1AL4MmhLWfmceyk6XXSqWaECh1YXC7aV')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('2- no hash. should return null ', () => {
|
|
31
|
-
const input = 'https://i.imgur.com/muESb0B.png'
|
|
32
|
-
|
|
33
|
-
expect(extractPHash(input)).toBe(null)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
describe('Proxify image src', () => {
|
|
38
|
-
it('1- should proxify image src', () => {
|
|
39
|
-
const input = 'https://i.imgur.com/muESb0B.png'
|
|
40
|
-
const expected = 'https://images.ecency.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgnJdyHYxb4dfF6gmC.png?format=match&mode=fit'
|
|
41
|
-
|
|
42
|
-
expect(proxifyImageSrc(input)).toBe(expected)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('2- should not proxify if already proxified', () => {
|
|
46
|
-
const input = 'https://images.ecency.com/0x0/https://i.imgur.com/muESb0B.png'
|
|
47
|
-
const expected = 'https://images.ecency.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgnJdyHYxb4dfF6gmC.png?format=match&mode=fit'
|
|
48
|
-
|
|
49
|
-
expect(proxifyImageSrc(input)).toBe(expected)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('3- set proxy base', () => {
|
|
53
|
-
setProxyBase('https://images.hive.blog')
|
|
54
|
-
|
|
55
|
-
const input = 'https://i.imgur.com/muESb0B.png'
|
|
56
|
-
const expected = 'https://images.hive.blog/p/2bP4pJr4wVimqCWjYimXJe2cnCgnJdyHYxb4dfF6gmC?format=match&mode=fit'
|
|
57
|
-
|
|
58
|
-
expect(proxifyImageSrc(input)).toBe(expected)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('4- replace already proxified', () => {
|
|
62
|
-
setProxyBase('https://images.ecency.com')
|
|
63
|
-
const input = 'https://images.hive.blog/60x70/http://hivebuzz.me/@hiveonboard/upvotes.png?202008050233'
|
|
64
|
-
const expected = 'https://images.ecency.com/60x70/http://hivebuzz.me/@hiveonboard/upvotes.png?202008050233'
|
|
65
|
-
|
|
66
|
-
expect(proxifyImageSrc(input)).toBe(expected)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('5- normal proxify for uploads', () => {
|
|
70
|
-
setProxyBase('https://images.ecency.com')
|
|
71
|
-
const input = 'https://images.hive.blog/DQmT7UTd6JTP3bB2fXzV6tv8u4cJ6fLijy2bUxatkLChzHD/IMG_6631.JPG'
|
|
72
|
-
const expected = 'https://images.ecency.com/p/Zskj9C56UonZ32EJw6nMctrTQ6kTQ3swaDmbMFtRtMzyrHs9JdvWTXeiP6cW6a7F6pv2A4qkeHLiAPVtmfYMDf3iYbydFZ7e8iYY4MZP74TgyWo8WnJa.png?format=match&mode=fit'
|
|
73
|
-
|
|
74
|
-
expect(proxifyImageSrc(input)).toBe(expected)
|
|
75
|
-
})
|
|
76
|
-
})
|
package/src/proxify-image-src.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import multihash from 'multihashes'
|
|
2
|
-
import querystring from 'querystring'
|
|
3
|
-
|
|
4
|
-
let proxyBase = 'https://images.ecency.com'
|
|
5
|
-
let fileExtension = true
|
|
6
|
-
|
|
7
|
-
export function setProxyBase(p: string): void {
|
|
8
|
-
proxyBase = p
|
|
9
|
-
fileExtension = proxyBase == 'https://images.ecency.com';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function extractPHash(url: string): string | null {
|
|
13
|
-
if (url.startsWith(`${proxyBase}/p/`)) {
|
|
14
|
-
const [hash] = url.split('/p/')[1].split('?')
|
|
15
|
-
return hash.replace(/.webp/,'').replace(/.png/,'')
|
|
16
|
-
}
|
|
17
|
-
return null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function isValidUrl(url: string): boolean {
|
|
21
|
-
try {
|
|
22
|
-
return Boolean(new URL(url));
|
|
23
|
-
}
|
|
24
|
-
catch(e){
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function getLatestUrl(str: string): string {
|
|
30
|
-
const [last] = [...str.replace(/https?:\/\//g, '\n$&').trim().split('\n')].reverse()
|
|
31
|
-
return last
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function proxifyImageSrc(url?: string, width = 0, height = 0, format = 'match') {
|
|
35
|
-
if (!url || typeof url !== 'string' || !isValidUrl(url)) {
|
|
36
|
-
return ''
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// skip images already proxified with images.hive.blog
|
|
40
|
-
if (url.indexOf('https://images.hive.blog/') === 0 && url.indexOf('https://images.hive.blog/D') !== 0) {
|
|
41
|
-
return url.replace('https://images.hive.blog', proxyBase)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (url.indexOf('https://steemitimages.com/') === 0 && url.indexOf('https://steemitimages.com/D') !== 0) {
|
|
45
|
-
return url.replace('https://steemitimages.com', proxyBase)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const realUrl = getLatestUrl(url)
|
|
49
|
-
const pHash = extractPHash(realUrl)
|
|
50
|
-
|
|
51
|
-
const options: Record<string, string | number> = {
|
|
52
|
-
format,
|
|
53
|
-
mode: 'fit',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (width > 0) {
|
|
57
|
-
options.width = width
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (height > 0) {
|
|
61
|
-
options.height = height
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const qs = querystring.stringify(options)
|
|
65
|
-
|
|
66
|
-
if (pHash) {
|
|
67
|
-
if (fileExtension) {
|
|
68
|
-
return `${proxyBase}/p/${pHash}${format==='webp'?'.webp':'.png'}?${qs}`
|
|
69
|
-
} else {
|
|
70
|
-
return `${proxyBase}/p/${pHash}?${qs}`
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const b58url = multihash.toB58String(Buffer.from(realUrl.toString()))
|
|
75
|
-
|
|
76
|
-
return `${proxyBase}/p/${b58url}${fileExtension ? format==='webp'?'.webp':'.png' : ''}?${qs}`
|
|
77
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { sanitizeHtml } from './methods/sanitize-html.method'
|
|
2
|
-
|
|
3
|
-
describe('sanitizeHtml', () => {
|
|
4
|
-
it('1- should allow video tag with src and controls', () => {
|
|
5
|
-
const input = '<video src="https://example.com/video.mp4" controls></video>'
|
|
6
|
-
const expected = '<video src="https://example.com/video.mp4" controls></video>'
|
|
7
|
-
expect(sanitizeHtml(input)).toBe(expected)
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('2- should strip dangerous video src', () => {
|
|
11
|
-
const input = "<video src=\"javascript:alert('XSS')\" controls></video>"
|
|
12
|
-
const expected = '<video controls></video>'
|
|
13
|
-
expect(sanitizeHtml(input)).toBe(expected)
|
|
14
|
-
})
|
|
15
|
-
})
|
package/src/test/data/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
|
|
3
|
-
export function getTestData(author: string, permlink: string): any {
|
|
4
|
-
const fileName = `${author}____${permlink}.json`
|
|
5
|
-
const readPath = `${__dirname}/json/${fileName}`
|
|
6
|
-
|
|
7
|
-
const raw = fs.readFileSync(readPath, 'utf-8')
|
|
8
|
-
|
|
9
|
-
return JSON.parse(raw)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const foo = 'foo'
|