@ecency/render-helper 2.4.11 → 2.4.13

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.
@@ -6,7 +6,7 @@ var multihash = require('multihashes');
6
6
  var querystring = require('querystring');
7
7
  var remarkable = require('remarkable');
8
8
  var linkify$1 = require('remarkable/linkify');
9
- var he = require('he');
9
+ var he2 = require('he');
10
10
  var htmlparser2 = require('htmlparser2');
11
11
  var domSerializerModule = require('dom-serializer');
12
12
  var lruCache = require('lru-cache');
@@ -34,7 +34,7 @@ function _interopNamespace(e) {
34
34
  var xss__default = /*#__PURE__*/_interopDefault(xss);
35
35
  var multihash__default = /*#__PURE__*/_interopDefault(multihash);
36
36
  var querystring__default = /*#__PURE__*/_interopDefault(querystring);
37
- var he__default = /*#__PURE__*/_interopDefault(he);
37
+ var he2__default = /*#__PURE__*/_interopDefault(he2);
38
38
  var htmlparser2__namespace = /*#__PURE__*/_interopNamespace(htmlparser2);
39
39
  var domSerializerModule__namespace = /*#__PURE__*/_interopNamespace(domSerializerModule);
40
40
 
@@ -1433,7 +1433,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1433
1433
  traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1434
1434
  output = serializer.serializeToString(doc);
1435
1435
  } catch (fallbackError) {
1436
- const escapedContent = he__default.default.encode(output || md.render(input));
1436
+ const escapedContent = he2__default.default.encode(output || md.render(input));
1437
1437
  output = `<p dir="auto">${escapedContent}</p>`;
1438
1438
  }
1439
1439
  }
@@ -1473,8 +1473,6 @@ function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.
1473
1473
  cacheSet(key, res);
1474
1474
  return res;
1475
1475
  }
1476
-
1477
- // src/catch-post-image.ts
1478
1476
  var gifLinkRegex = /\.(gif)$/i;
1479
1477
  function isGifLink(link) {
1480
1478
  return gifLinkRegex.test(link);
@@ -1491,12 +1489,20 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1491
1489
  }
1492
1490
  }
1493
1491
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
1494
- if (isGifLink(meta.image)) {
1495
- return proxifyImageSrc(meta.image, 0, 0, format);
1492
+ const decodedImage = he2__default.default.decode(meta.image);
1493
+ if (isGifLink(decodedImage)) {
1494
+ return proxifyImageSrc(decodedImage, 0, 0, format);
1496
1495
  }
1497
- return proxifyImageSrc(meta.image, width, height, format);
1496
+ return proxifyImageSrc(decodedImage, width, height, format);
1498
1497
  }
1499
1498
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
1499
+ if (typeof meta.image[0] === "string") {
1500
+ const decodedImage = he2__default.default.decode(meta.image[0]);
1501
+ if (isGifLink(decodedImage)) {
1502
+ return proxifyImageSrc(decodedImage, 0, 0, format);
1503
+ }
1504
+ return proxifyImageSrc(decodedImage, width, height, format);
1505
+ }
1500
1506
  if (isGifLink(meta.image[0])) {
1501
1507
  return proxifyImageSrc(meta.image[0], 0, 0, format);
1502
1508
  }
@@ -1513,20 +1519,34 @@ function getImage(entry, width = 0, height = 0, format = "match") {
1513
1519
  if (!src) {
1514
1520
  return null;
1515
1521
  }
1516
- if (isGifLink(src)) {
1517
- return proxifyImageSrc(src, 0, 0, format);
1522
+ const decodedSrc = he2__default.default.decode(src);
1523
+ if (isGifLink(decodedSrc)) {
1524
+ return proxifyImageSrc(decodedSrc, 0, 0, format);
1518
1525
  }
1519
- return proxifyImageSrc(src, width, height, format);
1526
+ return proxifyImageSrc(decodedSrc, width, height, format);
1520
1527
  }
1521
1528
  return null;
1522
1529
  }
1523
1530
  function catchPostImage(obj, width = 0, height = 0, format = "match") {
1524
1531
  if (typeof obj === "string") {
1525
- const entryWrapper = {
1526
- body: obj,
1527
- json_metadata: "{}"
1528
- };
1529
- return getImage(entryWrapper, width, height, format);
1532
+ const html = markdown2Html(obj);
1533
+ const doc = createDoc(html);
1534
+ if (!doc) {
1535
+ return null;
1536
+ }
1537
+ const imgEls = doc.getElementsByTagName("img");
1538
+ if (imgEls.length >= 1) {
1539
+ const src = imgEls[0].getAttribute("src");
1540
+ if (!src) {
1541
+ return null;
1542
+ }
1543
+ const decodedSrc = he2__default.default.decode(src);
1544
+ if (isGifLink(decodedSrc)) {
1545
+ return proxifyImageSrc(decodedSrc, 0, 0, format);
1546
+ }
1547
+ return proxifyImageSrc(decodedSrc, width, height, format);
1548
+ }
1549
+ return null;
1530
1550
  }
1531
1551
  const key = `${makeEntryCacheKey(obj)}-${width}x${height}-${format}`;
1532
1552
  const item = cacheGet(key);
@@ -1613,7 +1633,7 @@ function postBodySummary(entryBody, length = 200, platform = "web") {
1613
1633
  text2 = joint(text2.split(" "), length);
1614
1634
  }
1615
1635
  if (text2) {
1616
- text2 = he__default.default.decode(text2);
1636
+ text2 = he2__default.default.decode(text2);
1617
1637
  }
1618
1638
  return text2;
1619
1639
  }