@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.
Files changed (155) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +171 -17
  3. package/dist/browser/index.d.ts +32 -0
  4. package/dist/browser/index.js +1556 -0
  5. package/dist/browser/index.js.map +1 -0
  6. package/dist/node/index.cjs +1575 -0
  7. package/dist/node/index.cjs.map +1 -0
  8. package/dist/node/index.mjs +1559 -0
  9. package/dist/node/index.mjs.map +1 -0
  10. package/package.json +49 -47
  11. package/lib/cache.d.ts +0 -3
  12. package/lib/cache.js +0 -21
  13. package/lib/cache.js.map +0 -1
  14. package/lib/catch-post-image.d.ts +0 -2
  15. package/lib/catch-post-image.js +0 -76
  16. package/lib/catch-post-image.js.map +0 -1
  17. package/lib/consts/allowed-attributes.const.d.ts +0 -2
  18. package/lib/consts/allowed-attributes.const.js +0 -71
  19. package/lib/consts/allowed-attributes.const.js.map +0 -1
  20. package/lib/consts/dom-parser.const.d.ts +0 -2
  21. package/lib/consts/dom-parser.const.js +0 -12
  22. package/lib/consts/dom-parser.const.js.map +0 -1
  23. package/lib/consts/index.d.ts +0 -5
  24. package/lib/consts/index.js +0 -22
  25. package/lib/consts/index.js.map +0 -1
  26. package/lib/consts/regexes.const.d.ts +0 -44
  27. package/lib/consts/regexes.const.js +0 -49
  28. package/lib/consts/regexes.const.js.map +0 -1
  29. package/lib/consts/section-list.const.d.ts +0 -1
  30. package/lib/consts/section-list.const.js +0 -24
  31. package/lib/consts/section-list.const.js.map +0 -1
  32. package/lib/consts/white-list.const.d.ts +0 -2
  33. package/lib/consts/white-list.const.js +0 -37
  34. package/lib/consts/white-list.const.js.map +0 -1
  35. package/lib/helper.d.ts +0 -6
  36. package/lib/helper.js +0 -72
  37. package/lib/helper.js.map +0 -1
  38. package/lib/index.d.ts +0 -8
  39. package/lib/index.js +0 -19
  40. package/lib/index.js.map +0 -1
  41. package/lib/markdown-2-html.d.ts +0 -2
  42. package/lib/markdown-2-html.js +0 -25
  43. package/lib/markdown-2-html.js.map +0 -1
  44. package/lib/methods/a.method.d.ts +0 -1
  45. package/lib/methods/a.method.js +0 -647
  46. package/lib/methods/a.method.js.map +0 -1
  47. package/lib/methods/clean-reply.method.d.ts +0 -1
  48. package/lib/methods/clean-reply.method.js +0 -37
  49. package/lib/methods/clean-reply.method.js.map +0 -1
  50. package/lib/methods/get-inner-html.method.d.ts +0 -1
  51. package/lib/methods/get-inner-html.method.js +0 -16
  52. package/lib/methods/get-inner-html.method.js.map +0 -1
  53. package/lib/methods/iframe.method.d.ts +0 -1
  54. package/lib/methods/iframe.method.js +0 -159
  55. package/lib/methods/iframe.method.js.map +0 -1
  56. package/lib/methods/img.method.d.ts +0 -4
  57. package/lib/methods/img.method.js +0 -50
  58. package/lib/methods/img.method.js.map +0 -1
  59. package/lib/methods/index.d.ts +0 -7
  60. package/lib/methods/index.js +0 -24
  61. package/lib/methods/index.js.map +0 -1
  62. package/lib/methods/linkify.method.d.ts +0 -1
  63. package/lib/methods/linkify.method.js +0 -56
  64. package/lib/methods/linkify.method.js.map +0 -1
  65. package/lib/methods/markdown-to-html.method.d.ts +0 -1
  66. package/lib/methods/markdown-to-html.method.js +0 -98
  67. package/lib/methods/markdown-to-html.method.js.map +0 -1
  68. package/lib/methods/noop.method.d.ts +0 -1
  69. package/lib/methods/noop.method.js +0 -6
  70. package/lib/methods/noop.method.js.map +0 -1
  71. package/lib/methods/p.method.d.ts +0 -1
  72. package/lib/methods/p.method.js +0 -11
  73. package/lib/methods/p.method.js.map +0 -1
  74. package/lib/methods/remove-child-nodes.method.d.ts +0 -1
  75. package/lib/methods/remove-child-nodes.method.js +0 -10
  76. package/lib/methods/remove-child-nodes.method.js.map +0 -1
  77. package/lib/methods/sanitize-html.method.d.ts +0 -1
  78. package/lib/methods/sanitize-html.method.js +0 -42
  79. package/lib/methods/sanitize-html.method.js.map +0 -1
  80. package/lib/methods/text.method.d.ts +0 -1
  81. package/lib/methods/text.method.js +0 -69
  82. package/lib/methods/text.method.js.map +0 -1
  83. package/lib/methods/traverse.method.d.ts +0 -3
  84. package/lib/methods/traverse.method.js +0 -38
  85. package/lib/methods/traverse.method.js.map +0 -1
  86. package/lib/post-body-summary.d.ts +0 -2
  87. package/lib/post-body-summary.js +0 -123
  88. package/lib/post-body-summary.js.map +0 -1
  89. package/lib/proxify-image-src.d.ts +0 -5
  90. package/lib/proxify-image-src.js +0 -86
  91. package/lib/proxify-image-src.js.map +0 -1
  92. package/lib/render-helper.js +0 -1
  93. package/lib/types/entry.interface.d.ts +0 -7
  94. package/lib/types/entry.interface.js +0 -3
  95. package/lib/types/entry.interface.js.map +0 -1
  96. package/lib/types/index.d.ts +0 -2
  97. package/lib/types/index.js +0 -19
  98. package/lib/types/index.js.map +0 -1
  99. package/lib/types/xss-white-list.interface.d.ts +0 -6
  100. package/lib/types/xss-white-list.interface.js +0 -3
  101. package/lib/types/xss-white-list.interface.js.map +0 -1
  102. package/src/cache.ts +0 -15
  103. package/src/catch-post-image.spec.ts +0 -144
  104. package/src/catch-post-image.ts +0 -78
  105. package/src/consts/allowed-attributes.const.ts +0 -69
  106. package/src/consts/dom-parser.const.ts +0 -6
  107. package/src/consts/index.ts +0 -5
  108. package/src/consts/regexes.const.ts +0 -46
  109. package/src/consts/section-list.const.ts +0 -20
  110. package/src/consts/white-list.const.ts +0 -33
  111. package/src/external-types/multihashes.d.ts +0 -3
  112. package/src/helper.spec.ts +0 -16
  113. package/src/helper.ts +0 -77
  114. package/src/index.ts +0 -18
  115. package/src/markdown-2-html.spec.ts +0 -1251
  116. package/src/markdown-2-html.ts +0 -25
  117. package/src/methods/a.method.ts +0 -791
  118. package/src/methods/clean-reply.method.ts +0 -32
  119. package/src/methods/get-inner-html.method.ts +0 -11
  120. package/src/methods/iframe.method.ts +0 -176
  121. package/src/methods/img.method.ts +0 -62
  122. package/src/methods/index.ts +0 -7
  123. package/src/methods/linkify.method.ts +0 -61
  124. package/src/methods/markdown-to-html.method.ts +0 -104
  125. package/src/methods/noop.method.ts +0 -1
  126. package/src/methods/p.method.ts +0 -6
  127. package/src/methods/remove-child-nodes.method.ts +0 -5
  128. package/src/methods/sanitize-html.method.ts +0 -32
  129. package/src/methods/text.method.ts +0 -77
  130. package/src/methods/traverse.method.ts +0 -33
  131. package/src/post-body-summary.spec.ts +0 -150
  132. package/src/post-body-summary.ts +0 -130
  133. package/src/proxify-image-src.spec.ts +0 -76
  134. package/src/proxify-image-src.ts +0 -77
  135. package/src/sanitize-html.spec.ts +0 -15
  136. package/src/test/data/index.ts +0 -12
  137. package/src/test/data/json/muratkbesiroglu____sci-fi-novel-underground-city-part-13.json +0 -2120
  138. package/src/test/data/json/steemitboard____steemitboard-notify-dunsky-20181210t153450000z.json +0 -47
  139. package/src/test/data/legacy/10.json +0 -5
  140. package/src/test/data/legacy/20.json +0 -5
  141. package/src/test/data/legacy/21.json +0 -5
  142. package/src/test/data/legacy/2112524.json +0 -5
  143. package/src/test/data/legacy/22.json +0 -5
  144. package/src/test/data/legacy/23.json +0 -5
  145. package/src/test/data/legacy/24.json +0 -5
  146. package/src/test/data/legacy/25.json +0 -5
  147. package/src/test/data/legacy/26.json +0 -5
  148. package/src/test/data/legacy/27.JSON +0 -5
  149. package/src/test/data/legacy/28.json +0 -5
  150. package/src/test/data/legacy/29.json +0 -5
  151. package/src/test/data/legacy/31.json +0 -5
  152. package/src/test/snaps.json +0 -8
  153. package/src/types/entry.interface.ts +0 -7
  154. package/src/types/index.ts +0 -2
  155. package/src/types/xss-white-list.interface.ts +0 -7
@@ -1,7 +0,0 @@
1
- export interface Entry {
2
- author?: string;
3
- permlink?: string;
4
- last_update?: string;
5
- body: any;
6
- json_metadata?: any;
7
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=entry.interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"entry.interface.js","sourceRoot":"","sources":["../../src/types/entry.interface.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export * from './entry.interface';
2
- export * from './xss-white-list.interface';
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./entry.interface"), exports);
18
- __exportStar(require("./xss-white-list.interface"), exports);
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,6DAA0C"}
@@ -1,6 +0,0 @@
1
- import { IWhiteList } from 'xss';
2
- export interface XSSWhiteList extends IWhiteList {
3
- iframe?: string[];
4
- strike?: string[];
5
- video?: string[];
6
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=xss-white-list.interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xss-white-list.interface.js","sourceRoot":"","sources":["../../src/types/xss-white-list.interface.ts"],"names":[],"mappings":""}
package/src/cache.ts DELETED
@@ -1,15 +0,0 @@
1
- import LRU from 'lru-cache'
2
-
3
- const cache = new LRU(60)
4
-
5
- export function setCacheSize(size: number): void {
6
- cache.max = size
7
- }
8
-
9
- export function cacheGet<T extends unknown>(key: string): T {
10
- return cache.get(key) as T
11
- }
12
-
13
- export function cacheSet(key: string, value: unknown): void {
14
- cache.set(key, value)
15
- }
@@ -1,144 +0,0 @@
1
- import { catchPostImage } from './catch-post-image'
2
-
3
- describe('catchPostImage', () => {
4
- it('1- Should extract entry image from json_metadata', () => {
5
- const input = {
6
- author: 'foo1',
7
- permlink: 'bar1',
8
- json_metadata:
9
- '{"tags":["auto","vehicle","ai","technology","adsactly"],"users":["adsactly","techblogger","adsactly-witness"],"image":["http://www.autonews.com/apps/pbcsi.dll/storyimage/CA/20180205/MOBILITY/180209919/AR/0/AR-180209919.jpg","http://clipart-library.com/images/pco56kbxi.png","http://psipunk.com/wp-content/uploads/2010/03/phoenix-electric-car-futuristic-concept-01.jpg","https://images.hgmsites.net/med/2011-honda-small-sports-ev-concept_100369472_m.jpg","https://cdn.trendhunterstatic.com/thumbs/electric-car-concept.jpeg","https://s.aolcdn.com/hss/storage/midas/162bec06fe31386c2a36ad6ca4d7f01d/205983934/lg-here-self-driving-car-partnership.jpg","https://images.ecency.com/DQmd5CQG5zLjjm2z8289qcLU6eBHJpC5FmgtR3aC1eXnhsi/Adsactly-Logo-200px.png","https://images.ecency.com/0x0/https://images.ecency.com/DQmWK9ACVoywHPBJQdoTuJpoTSoaubBSKSAdZaJtw1cfLb9/adsactlywitness.gif"],"links":["https://qzprod.files.wordpress.com/2018/02/kelly-sikkema-266805.jpg?quality=80&strip=all&w=3200","http://psipunk.com/wp-content/uploads/2010/03/phoenix-electric-car-futuristic-concept-01.jpg","https://images.hgmsites.net/med/2011-honda-small-sports-ev-concept_100369472_m.jpg","https://cdn.trendhunterstatic.com/thumbs/electric-car-concept.jpeg","https://s.aolcdn.com/hss/storage/midas/162bec06fe31386c2a36ad6ca4d7f01d/205983934/lg-here-self-driving-car-partnership.jpg","https://discord.gg/EwGhEzb","https://steemit.com/witness-category/@adsactly-witness/adsactly-steemit-witness-proposal","https://steemit.com/~witnesses","https://v2.steemconnect.com/sign/account-witness-vote?witness=adsactly-witness&approve=1"],"app":"steemit/0.1","format":"markdown"}',
10
- body: '',
11
- last_update: '2019-05-10T09:15:21'
12
- }
13
-
14
- const expected = 'https://images.ecency.com/p/2N61tysBoFrHXFxZDViD89h3bB1XeSgVQ4AKkLUBP2yqmAVL2ZqehqfzwxCQq2g82mHjH9LZV4ugYdmL4TbpNqAoc5LaDDRVPYNurZeK7HpTFq6fjtFG1s9ZpXZWuCufpLhZsDw1G1wL.png?format=match&mode=fit'
15
-
16
- expect(catchPostImage(input)).toBe(expected)
17
- })
18
-
19
- it('2- Should extract entry image from json_metadata', () => {
20
- const input = {
21
- author: 'foo2',
22
- permlink: 'bar2',
23
- json_metadata:
24
- '{"community":"busy","app":"busy/2.3.0","format":"markdown","users":["gavvet","kingscrown","vcelier","ezzy","meesterboom","thecryptodrive","reggaemuffin","adsactly","adsactly-witness","buildteam","minnowbooster","steemvoter","steemsports"],"links":["https://imgur.com/NUt92kg","/@gavvet","/@kingscrown","/@vcelier","/@ezzy","/@meesterboom","/@thecryptodrive","/@reggaemuffin","/@adsactly","/@adsactly-witness"],"image":["https://images.ecency.com/0x0/https://i.imgur.com/NUt92kg.jpg","https://images.ecency.com/0x0/https://images.ecency.com/DQmXndfFUQmmtMk5Dd6u1nRNmNqr2mdkEGDVkT9SNyCxEeP/bt%20logo.png","https://images.ecency.com/0x0/https://images.ecency.com/DQmd5CQG5zLjjm2z8289qcLU6eBHJpC5FmgtR3aC1eXnhsi/Adsactly-Logo-200px.png"],"tags":["art","photography","adsactly","thoughts","busy"]}',
25
- body: '',
26
- last_update: '2019-05-10T09:15:21'
27
- }
28
-
29
- const expected = 'https://images.ecency.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgnAvKo1Rap9w75mXk.png?format=match&mode=fit'
30
-
31
- expect(catchPostImage(input)).toBe(expected)
32
- })
33
-
34
- it('3- Should extract nothing from json_metadata because there is no image field ', () => {
35
- const input = {
36
- author: 'foo3',
37
- permlink: 'bar3',
38
- json_metadata:
39
- '{"video":{"info":{"title":"HEALTHY SERIES | LUNCH | STUFFED AUBERGINE BOATS - VIDEO ","snaphash":"QmdbBjr9bhab392f2zkXsa7YhHue7YNch2J1XXzvhLEE6V","author":"allasyummyfood","permlink":"qe5nlzmj","duration":172.384943,"filesize":26936060,"spritehash":"QmSG49VefmCQqWVjb8ii79GQVuSSKrFrUNSh45gni5Kqhq"},"content":{"videohash":"QmRkNLhhBjr86YB21ZpD76A1jCDt7stCAMeNpWgxNYRmUs","video480hash":"QmP3S6piVPRuriPmQZRbPPHGYG5aKYjukFP8vWWcW349VQ","magnet":"","description":"How to make stuffed eggplant. Looking for a flavorful dinner? Then try this baked eggplant dish that\'s stuffed with vegetables and spices. Make the most of whole aubergines - turn them into edible bowls. Serve these stuffed aubergines as a light dinner along with a big salad. This is very hearty and nutritious dish.\\n\\nIngredients \\n\\n\\n1 large aubergine\\n1 cup - 200 gr of chopped canned tomato\\n1 tsp of turmeric and 1tsp of cumin\\nhalf an onion\\n2 cloves of garlic\\nbunch of parsley\\nsalt & pepper\\nsour cream ( optional)\\n\\nDirections \\n\\nStep 1: Preheat your oven to 180 C or 350 F.\\nStep 2 : Cut your eggplant in half, make few cuts along and then across. \\nStep 3 : Place your eggplant onto a baking dish, blush them with olive oil or use low calorie cooking spray. \\nStep 4 : Cook your eggplant for 30-35 min. \\nStep 5 : In a small saucepan, place your chopped onion and garlic. Fry for 3 -5 min untill soft. Add turmeric and cumin. Then add chopped tomatoes, \\nStep 6 : Scoop the mixture from your eggplant very carefully without breaking the skin. \\nStep 7 : Add the eggplant flesh into your pan along with parsley and cook for 15 min on low heat.\\nStep 8 : Fill your eggplant boats and serve with some fresh sour cream. \\n\\nMore videos on @dtube!!! :))) Alla \\n","tags":["dtube","video","food","recipe"]},"_id":"d46a5cfac370f095a54e6aa088656d7e"},"tags":["dtube","video","food","recipe","dtube"],"app":"dtube/0.6"}',
40
- body: '',
41
- last_update: '2019-05-10T09:15:21'
42
- }
43
- expect(catchPostImage(input)).toBe(null)
44
- })
45
-
46
- it('4- Should extract entry image from image link', () => {
47
- const input = {
48
- author: 'foo4',
49
- permlink: 'bar4',
50
- json_metadata: '{}',
51
- body: '<center>https://ipfs.io/ipfs/aa.png</center><hr>',
52
- last_update: '2019-05-10T09:15:21'
53
- }
54
-
55
- const expected = 'https://images.ecency.com/p/F7pXcna7voXwGzRSmsevszxeTZTcnhJVu7akN.png?format=match&mode=fit'
56
-
57
- expect(catchPostImage(input)).toBe(expected)
58
- })
59
-
60
- it('5- Should extract entry image from img tag', () => {
61
- const input = {
62
- author: 'foo5',
63
- permlink: 'bar5',
64
- body:
65
- '<center><a href=\'https://d.tube/#!/v/theaudgirl/2ys21z9c\'><img src=\'https://ipfs.io/ipfs/QmaG5Dpg1XGiY7EyeMCwT8Dqw4GfiAaehq3hZadongniQc\'></a></center><hr>',
66
- last_update: '2019-05-10T09:15:21'
67
- }
68
-
69
- const expected = 'https://images.ecency.com/p/46aP2QbqUqBqwzwxM6L1P6uLNceBDDCMCT7ReED4mRE2QxpU6UqBLE8rB5qCFGv3PRxu6pX61M3gUWVEEkTHbKBUQ2Kc.png?format=match&mode=fit'
70
-
71
- expect(catchPostImage(input)).toBe(expected)
72
- })
73
-
74
- it('6- Should extract entry image from markdown img tag', () => {
75
- const input = {
76
- author: 'foo6',
77
- permlink: 'bar6',
78
- json_metadata: '{}',
79
- body:
80
- '<center>![ezrni9y9pw.jpg](https://img.esteem.ws/ezrni9y9pw.jpg)</center><hr>',
81
- last_update: '2019-05-10T09:15:21'
82
- }
83
-
84
- const expected = 'https://images.ecency.com/p/o1AJ9qDyyJNSpZWhUgGYc3MngFqoAMxpZmncLuDWMUeztZaUN.png?format=match&mode=fit'
85
-
86
- expect(catchPostImage(input)).toBe(expected)
87
- })
88
-
89
- it('7- Should extract nothing', () => {
90
- const input = {
91
- author: 'foo7',
92
- permlink: 'bar7',
93
- json_metadata: '{}',
94
- body: '<p>lorem ipsum dolor</p> sit amet',
95
- last_update: '2019-05-10T09:15:21'
96
- }
97
-
98
- expect(catchPostImage(input)).toBe(null)
99
- })
100
-
101
- it('8- Test with not obj param', () => {
102
- const input = '<center>![ezrni9y9pw.jpg](https://img.esteem.ws/ezrni9y9pw.jpg)</center><hr>'
103
- const expected = 'https://images.ecency.com/p/o1AJ9qDyyJNSpZWhUgGYc3MngFqoAMxpZmncLuDWMUeztZaUN.png?format=match&mode=fit'
104
-
105
- expect(catchPostImage(input)).toBe(expected)
106
- })
107
-
108
- it('9- Should catch from new post style', () => {
109
- const input = {
110
- 'json_metadata': {
111
- 'image': ['https://files.peakd.com/file/peakd-hive/aggroed/agtirkG8-image.png', 'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.adafruit.com%2Fblog%2Fwp-content%2Fuploads%2F2014%2F04%2Fgeordi-la-forge-600x458.jpg&amp;f=1&amp;nofb=1']
112
- }
113
- }
114
-
115
- const expected = 'https://images.ecency.com/p/hgjbks2vRxvf3xsYr6qQ7dm31DuBHGui8pKMdEVPxhLfEeEoVMPfUw4Z6QduNMpLay65R9vadbefhmDKmhM6HD8w8a.png?format=match&mode=fit'
116
-
117
- expect(catchPostImage(input as any)).toBe(expected)
118
- })
119
-
120
- it('10- Image field can contain only string ', () => {
121
- const input = {
122
- author: 'foo-10',
123
- permlink: 'bar-baz-10',
124
- json_metadata: {
125
- image: [
126
- [
127
- '![](https://cdn.steemitimages.com/DQmecSNtkk82zz62rymdK7wvXujn5P47zkARUMR13QLXmya/image.png)'
128
- ]
129
- ]
130
- }
131
- }
132
- expect(catchPostImage(input as any)).toBe('')
133
- })
134
-
135
- it('11- Image field is string', () => {
136
- const input = {
137
- 'json_metadata': {
138
- 'image': 'https://files.peakd.com/file/peakd-hive/aggroed/agtirkG8-image.png'
139
- }
140
- }
141
- const expected = 'https://images.ecency.com/p/hgjbks2vRxvf3xsYr6qQ7dm31DuBHGui8pKMdEVPxhLfEeEoVMPfUw4Z6QduNMpLay65R9vadbefhmDKmhM6HD8w8a.png?format=match&mode=fit'
142
- expect(catchPostImage(input as any)).toBe(expected)
143
- })
144
- })
@@ -1,78 +0,0 @@
1
- import { proxifyImageSrc } from './proxify-image-src'
2
- import { markdown2Html } from './markdown-2-html'
3
- import { createDoc, makeEntryCacheKey } from './helper'
4
- import { cacheGet, cacheSet } from './cache'
5
- import { Entry } from './types'
6
-
7
- const gifLinkRegex = /\.(gif)$/i;
8
-
9
- function isGifLink(link: string) {
10
- return gifLinkRegex.test(link);
11
- }
12
-
13
- function getImage(entry: Entry, width = 0, height = 0, format = 'match'): string | null {
14
- /*
15
- * Return from json metadata if exists
16
- * */
17
- let meta: Entry['json_metadata'] | null
18
-
19
- if (typeof entry.json_metadata === 'object') {
20
- meta = entry.json_metadata
21
- } else {
22
- try {
23
- meta = JSON.parse(entry.json_metadata as string)
24
- } catch (e) {
25
- meta = null
26
- }
27
- }
28
-
29
- if (meta && typeof meta.image === 'string' && meta.image.length > 0) {
30
- if (isGifLink(meta.image)) {
31
- return proxifyImageSrc(meta.image, 0, 0, format)
32
- }
33
- return proxifyImageSrc(meta.image, width, height, format)
34
- }
35
-
36
- if (meta && meta.image && !!meta.image.length && meta.image[0]) {
37
- if (isGifLink(meta.image[0])) {
38
- return proxifyImageSrc(meta.image[0], 0, 0, format)
39
- }
40
- return proxifyImageSrc(meta.image[0], width, height, format)
41
- }
42
-
43
- // try to find first image from post body
44
- const html = markdown2Html(entry)
45
- const doc = createDoc(html)
46
- if (!doc) {
47
- return null
48
- }
49
-
50
- const imgEls = doc.getElementsByTagName('img')
51
- if (imgEls.length >= 1) {
52
- const src = imgEls[0].getAttribute('src')
53
- if (isGifLink(src)) {
54
- return proxifyImageSrc(src, 0, 0, format)
55
- }
56
- return proxifyImageSrc(src, width, height, format)
57
- }
58
-
59
- return null
60
- }
61
-
62
- export function catchPostImage(obj: Entry | string, width = 0, height = 0, format = 'match'): string {
63
- if (typeof obj === 'string') {
64
- return getImage(obj as any, width, height, format)
65
- }
66
- const key = `${makeEntryCacheKey(obj)}-${width}x${height}-${format}`
67
-
68
- const item = cacheGet<string>(key)
69
- if (item) {
70
- return item
71
- }
72
-
73
- const res = getImage(obj, width, height, format)
74
- cacheSet(key, res)
75
-
76
- return res
77
- }
78
-
@@ -1,69 +0,0 @@
1
- import { XSSWhiteList } from '../types'
2
-
3
- export const ALLOWED_ATTRIBUTES: XSSWhiteList = {
4
- 'a': [
5
- 'href',
6
- 'target',
7
- 'rel',
8
- 'data-permlink',
9
- 'data-tag',
10
- 'data-author',
11
- 'data-href',
12
- 'data-community',
13
- 'data-filter',
14
- 'data-embed-src',
15
- 'data-youtube',
16
- 'data-start-time',
17
- 'data-video-href',
18
- 'data-proposal',
19
- 'data-is-inline',
20
- 'class',
21
- 'title',
22
- 'data-id',
23
- 'id'
24
- ],
25
- 'img': [
26
- 'src',
27
- 'alt',
28
- 'class',
29
- 'loading',
30
- 'fetchpriority',
31
- 'decoding',
32
- 'itemprop'
33
- ],
34
- 'span': ['class', 'id', 'data-align'],
35
- 'iframe': ['src', 'class', 'frameborder', 'allowfullscreen', 'webkitallowfullscreen', 'mozallowfullscreen', 'sandbox'],
36
- 'video': ['src', 'controls', 'poster'],
37
- 'div': ['class', 'id', 'data-align'],
38
- 'strong': [],
39
- 'b': [],
40
- 'i': [],
41
- 'strike': [],
42
- 'em': [],
43
- 'code': [],
44
- 'pre': [],
45
- 'blockquote': ['class'],
46
- 'sup': [],
47
- 'sub': [],
48
- 'h1': ['dir', 'id', 'data-align'],
49
- 'h2': ['dir', 'id', 'data-align'],
50
- 'h3': ['dir', 'id', 'data-align'],
51
- 'h4': ['dir', 'id', 'data-align'],
52
- 'h5': ['dir', 'id', 'data-align'],
53
- 'h6': ['dir', 'id', 'data-align'],
54
- 'p': ['dir', 'id', 'data-align'],
55
- 'center': [],
56
- 'ul': [],
57
- 'ol': [],
58
- 'li': [],
59
- 'table': [],
60
- 'thead': [],
61
- 'tbody': [],
62
- 'tr': [],
63
- 'td': [],
64
- 'th': [],
65
- 'hr': [],
66
- 'br': [],
67
- 'del': [],
68
- 'ins': []
69
- }
@@ -1,6 +0,0 @@
1
- import xmldom from 'xmldom'
2
- import { noop } from '../methods/noop.method'
3
-
4
- export const DOMParser = new xmldom.DOMParser({
5
- errorHandler: { warning: noop, error: noop }
6
- })
@@ -1,5 +0,0 @@
1
- export * from './white-list.const'
2
- export * from './section-list.const'
3
- export * from './regexes.const'
4
- export * from './allowed-attributes.const'
5
- export * from './dom-parser.const'
@@ -1,46 +0,0 @@
1
- // link regex
2
- export const URL_REGEX = /(https?:\/\/[^\s]+)/g
3
- export const IMG_REGEX = /(https?:\/\/.*\.(?:tiff?|jpe?g|gif|png|svg|ico|heic|webp))(.*)/gim
4
- export const IPFS_REGEX = /^https?:\/\/[^/]+\/(ip[fn]s)\/([^/?#]+)/gim
5
- export const POST_REGEX = /^https?:\/\/(.*)\/(.*)\/(@[\w.\d-]+)\/(.*)/i
6
- export const CCC_REGEX = /^https?:\/\/(.*)\/ccc\/([\w.\d-]+)\/(.*)/i
7
- export const MENTION_REGEX = /^https?:\/\/(.*)\/(@[\w.\d-]+)$/i
8
- export const TOPIC_REGEX = /^https?:\/\/(.*)\/(trending|hot|created|promoted|muted|payout)\/(.*)$/i
9
- export const INTERNAL_MENTION_REGEX = /^\/@[\w.\d-]+$/i
10
- export const INTERNAL_TOPIC_REGEX = /^\/(trending|hot|created|promoted|muted|payout)\/(.*)$/i
11
- export const INTERNAL_POST_TAG_REGEX = /(.*)\/(@[\w.\d-]+)\/(.*)/i
12
- export const INTERNAL_POST_REGEX = /^\/(@[\w.\d-]+)\/(.*)$/i
13
- export const CUSTOM_COMMUNITY_REGEX = /^https?:\/\/(.*)\/c\/(hive-\d+)(.*)/i
14
- export const YOUTUBE_REGEX = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|shorts\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/g
15
- export const YOUTUBE_EMBED_REGEX = /^(https?:)?\/\/www.youtube.com\/(embed|shorts)\/.*/i
16
- export const VIMEO_REGEX = /(https?:\/\/)?(www\.)?(?:vimeo)\.com.*(?:videos|video|channels|)\/([\d]+)/i
17
- export const VIMEO_EMBED_REGEX = /https:\/\/player\.vimeo\.com\/video\/([0-9]+)/
18
- export const BITCHUTE_REGEX = /^(?:https?:\/\/)?(?:www\.)?bitchute.com\/(?:video|embed)\/([a-z0-9]+)/i
19
- export const D_TUBE_REGEX = /(https?:\/\/d.tube.#!\/v\/)(\w+)\/(\w+)/g
20
- export const D_TUBE_REGEX2 = /(https?:\/\/d.tube\/v\/)(\w+)\/(\w+)/g
21
- export const D_TUBE_EMBED_REGEX = /^https:\/\/emb.d.tube\/.*/i
22
- export const TWITCH_REGEX = /https?:\/\/(?:www.)?twitch.tv\/(?:(videos)\/)?([a-zA-Z0-9][\w]{3,24})/i
23
- export const DAPPLR_REGEX = /^(https?:)?\/\/[a-z]*\.dapplr.in\/file\/dapplr-videos\/.*/i
24
- export const TRUVVL_REGEX = /^https?:\/\/embed.truvvl.com\/(@[\w.\d-]+)\/(.*)/i
25
- export const LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/.*/i
26
- export const ODYSEE_REGEX = /^(https?:)?\/\/odysee\.com\/(?:\$|%24)\/embed\/.*/i
27
- export const SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i
28
- export const ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/.*/i
29
- export const SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i
30
- export const SPEAK_EMBED_REGEX = /^(https?:)?\/\/3speak.([a-z]+)\/embed\?.*/i
31
- export const TWITTER_REGEX = /(?:https?:\/\/(?:(?:twitter\.com\/(.*?)\/status\/(.*))))/gi
32
- export const SPOTIFY_REGEX = /^https:\/\/open\.spotify\.com\/playlist\/(.*)?$/gi
33
- export const RUMBLE_REGEX = /^https:\/\/rumble.com\/embed\/([a-zA-Z0-9-]+)\/\?pub=\w+/
34
- export const BRIGHTEON_REGEX = /^https?:\/\/(www\.)?brighteon\.com\/(?:embed\/)?(.*[0-9].*)/i
35
- export const VIMM_EMBED_REGEX = /^https:\/\/www.vimm.tv\/.*/i
36
- export const SPOTIFY_EMBED_REGEX = /^https:\/\/open\.spotify\.com\/(embed|embed-podcast)\/(playlist|show|episode|track|album)\/(.*)/i
37
- export const SOUNDCLOUD_EMBED_REGEX = /^https:\/\/w.soundcloud.com\/player\/.*/i
38
- export const TWITCH_EMBED_REGEX = /^(https?:)?\/\/player.twitch.tv\/.*/i
39
- export const BRAND_NEW_TUBE_REGEX = /^https:\/\/brandnewtube\.com\/embed\/[a-z0-9]+$/i
40
- export const LOOM_REGEX = /^(https?:)?\/\/www.loom.com\/share\/(.*)/i
41
- export const LOOM_EMBED_REGEX = /^(https?:)?\/\/www.loom.com\/embed\/(.*)/i
42
- export const AUREAL_EMBED_REGEX = /^(https?:\/\/)?(www\.)?(?:aureal-embed)\.web\.app\/([0-9]+)/i
43
- export const ENTITY_REGEX = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/ig
44
- export const SECTION_REGEX = /\B(\#[\da-zA-Z-_]+\b)(?!;)/i
45
- export const ID_WHITELIST = /^[A-Za-z][-A-Za-z0-9_]*$/
46
-
@@ -1,20 +0,0 @@
1
- export const SECTION_LIST = [
2
- 'wallet',
3
- 'feed',
4
- 'followers',
5
- 'following',
6
- 'points',
7
- 'communities',
8
- 'posts',
9
- 'blog',
10
- 'comments',
11
- 'replies',
12
- 'settings',
13
- 'engine',
14
- 'permissions',
15
- 'referrals',
16
- 'payout',
17
- 'activities',
18
- 'spk',
19
- 'trail'
20
- ]
@@ -1,33 +0,0 @@
1
- export const WHITE_LIST = [
2
- 'ecency.com',
3
- 'hive.blog',
4
- 'peakd.com',
5
- 'travelfeed.io',
6
- 'dapplr.in',
7
- 'leofinance.io',
8
- 'inleo.io',
9
- 'proofofbrain.io',
10
- 'stemgeeks.net',
11
- 'hiveblockexplorer.com',
12
- 'proofofbrain.blog',
13
- 'weedcash.network',
14
- 'dapplr.in',
15
- 'liketu.com',
16
- 'bilpcoin.com',
17
- 'inji.com'
18
- ]
19
- export const OLD_LIST = [
20
- 'busy.org',
21
- 'steemit.com',
22
- 'esteem.app',
23
- 'steempeak.com',
24
- 'partiko.app',
25
- 'chainbb.com',
26
- 'utopian.io',
27
- 'steemkr.com',
28
- 'strimi.pl',
29
- 'steemhunt.com',
30
- 'ulogs.org',
31
- 'hede.io',
32
- 'naturalmedicine.io'
33
- ]
@@ -1,3 +0,0 @@
1
- declare module 'multihashes' {
2
- function toB58String(buffer: Buffer): string
3
- }
@@ -1,16 +0,0 @@
1
- import { makeEntryCacheKey } from './helper'
2
-
3
- describe('Helper', () => {
4
- it('1- makeEntryCacheKey', () => {
5
- const input = {
6
- author: 'foo1',
7
- permlink: 'bar1',
8
- last_update: '2019-05-10T09:15:21',
9
- updated: ''
10
- }
11
-
12
- const expected = 'foo1-bar1-2019-05-10T09:15:21-'
13
-
14
- expect(makeEntryCacheKey(input)).toBe(expected)
15
- })
16
- })
package/src/helper.ts DELETED
@@ -1,77 +0,0 @@
1
- import { DOMParser } from './consts'
2
-
3
- export function createDoc(html: string): Document | null {
4
- if (html.trim() === '') {
5
- return null
6
- }
7
-
8
- const doc = DOMParser.parseFromString(html, 'text/html')
9
-
10
- return doc
11
- }
12
-
13
- export function makeEntryCacheKey(entry: any): string {
14
- return `${entry.author}-${entry.permlink}-${entry.last_update}-${entry.updated}`
15
- }
16
-
17
- export function extractYtStartTime(url:string):string {
18
- try {
19
- const urlObj = new URL(url);
20
- const params = new URLSearchParams(urlObj.search);
21
- if(params.has('t')){
22
- return '' + parseInt(params.get('t')); //parsing is important as sometimes t is famated '123s';
23
- }else if (params.has('start')){
24
- return params.get('start');
25
- }
26
- } catch (error) {
27
- return '';
28
- }
29
- }
30
- export function sanitizePermlink(permlink: string): string {
31
- if (!permlink || typeof permlink !== 'string') {
32
- return ''
33
- }
34
-
35
- const [withoutQuery] = permlink.split('?')
36
- const [cleaned] = withoutQuery.split('#')
37
-
38
- return cleaned
39
- }
40
-
41
- export function isValidPermlink(permlink: string): boolean {
42
- const sanitized = sanitizePermlink(permlink)
43
-
44
- if (!sanitized) {
45
- return false
46
- }
47
-
48
- // Should not contain image extensions, query params, or fragments
49
- const isImage = /\.(jpg|jpeg|png|webp|gif|svg)$/i.test(sanitized)
50
- const isCleanFormat = /^[a-z0-9-]+$/.test(sanitized) // Hive standard
51
-
52
- return isCleanFormat && !isImage
53
- }
54
-
55
- // Reference: https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax
56
- // Hive account names must follow similar rules to DNS (RFC 1035)
57
- const LABEL_REGEX = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
58
-
59
- export function isValidUsername(username: string): boolean {
60
- if (!username || typeof username !== 'string') return false;
61
- if (username.length > 16) return false;
62
-
63
- const labels = username.split('.');
64
-
65
- return labels.every(label => {
66
- return (
67
- label.length >= 3 &&
68
- label.length <= 16 &&
69
- /^[a-z]/.test(label) && // must start with a letter
70
- LABEL_REGEX.test(label) && // a-z0-9, hyphens, no start/end hyphen
71
- !label.includes('..') // double dots are impossible after split, but just in case
72
- );
73
- });
74
- }
75
-
76
-
77
-
package/src/index.ts DELETED
@@ -1,18 +0,0 @@
1
- import { markdown2Html as renderPostBody } from './markdown-2-html'
2
- import { catchPostImage } from './catch-post-image'
3
- import { getPostBodySummary as postBodySummary } from './post-body-summary'
4
- import { setProxyBase, proxifyImageSrc } from './proxify-image-src'
5
- import { setCacheSize } from './cache'
6
- import { SECTION_LIST } from './consts'
7
- import { isValidPermlink } from "./helper";
8
-
9
- export {
10
- renderPostBody,
11
- catchPostImage,
12
- postBodySummary,
13
- proxifyImageSrc,
14
- setProxyBase,
15
- setCacheSize,
16
- SECTION_LIST,
17
- isValidPermlink
18
- }