@ecency/render-helper 2.5.23 → 2.5.24

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.
@@ -629,6 +629,40 @@ function isValidUrl(url) {
629
629
  return false;
630
630
  }
631
631
  }
632
+ var MAX_PROXIED_URL_LENGTH = 2048;
633
+ var LEGACY_SIZED_PROXY_RE = /^https:\/\/(?:images\.hive\.blog|steemitimages\.com)\/\d+x\d+\/(.+)$/;
634
+ function isLegacySizedProxyUrl(url) {
635
+ if (!url || typeof url !== "string") return false;
636
+ return LEGACY_SIZED_PROXY_RE.test(url);
637
+ }
638
+ function extractLegacySizedSource(url) {
639
+ const m = LEGACY_SIZED_PROXY_RE.exec(url);
640
+ if (!m) return null;
641
+ const rest = m[1];
642
+ const hashIndex = rest.indexOf("#");
643
+ const addressable = hashIndex >= 0 ? rest.slice(0, hashIndex) : rest;
644
+ const qIndex = addressable.indexOf("?");
645
+ const path = qIndex >= 0 ? addressable.slice(0, qIndex) : addressable;
646
+ const query = qIndex >= 0 ? addressable.slice(qIndex + 1) : "";
647
+ let end = path.length;
648
+ while (end > 0 && path.charCodeAt(end - 1) === 47) {
649
+ end--;
650
+ }
651
+ try {
652
+ const inner = new URL(path.slice(0, end));
653
+ if (query) {
654
+ for (const [key, value] of new URLSearchParams(query)) {
655
+ inner.searchParams.append(key, value);
656
+ }
657
+ }
658
+ return inner.toString();
659
+ } catch {
660
+ return null;
661
+ }
662
+ }
663
+ function isLegacyForeignProxyUrl(url) {
664
+ return url.indexOf("https://images.hive.blog/") === 0 && url.indexOf("https://images.hive.blog/D") !== 0 || url.indexOf("https://steemitimages.com/") === 0 && url.indexOf("https://steemitimages.com/D") !== 0;
665
+ }
632
666
  function getLatestUrl(str) {
633
667
  const [last] = [...str.replace(/https?:\/\//g, "\n$&").trim().split("\n")].reverse();
634
668
  return last;
@@ -637,17 +671,17 @@ function proxifyForFormat(url, width = 0, height = 0, format = "match", opts = {
637
671
  if (!url || typeof url !== "string" || !isValidUrl(url)) {
638
672
  return "";
639
673
  }
640
- const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
641
- if (url.indexOf("https://images.hive.blog/") === 0 && url.indexOf("https://images.hive.blog/D") !== 0) {
642
- return url.replace("https://images.hive.blog", proxyBase);
674
+ if (url.length > MAX_PROXIED_URL_LENGTH) {
675
+ return "";
643
676
  }
644
- if (url.indexOf("https://steemitimages.com/") === 0 && url.indexOf("https://steemitimages.com/D") !== 0) {
645
- return url.replace("https://steemitimages.com", proxyBase);
677
+ const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
678
+ if (isLegacyForeignProxyUrl(url) && !(isLegacySizedProxyUrl(url) && routeThroughProxy)) {
679
+ return url.replace("https://images.hive.blog", proxyBase).replace("https://steemitimages.com", proxyBase);
646
680
  }
647
681
  if (url.indexOf("https://images.ecency.com/") === 0 && !routeThroughProxy) {
648
682
  return url.replace("https://images.ecency.com", proxyBase);
649
683
  }
650
- const realUrl = getLatestUrl(url);
684
+ const realUrl = extractLegacySizedSource(url) ?? getLatestUrl(url);
651
685
  const pHash = extractPHash(realUrl);
652
686
  const options = {
653
687
  format,
@@ -707,6 +741,7 @@ function isPictureEligibleRawUrl(rawUrl) {
707
741
  return false;
708
742
  }
709
743
  if (u.protocol !== "http:" && u.protocol !== "https:") return false;
744
+ if (isLegacySizedProxyUrl(rawUrl)) return true;
710
745
  const host = `${u.protocol}//${u.host}`;
711
746
  const isProxyHost = host === proxyBase || host === "https://images.ecency.com";
712
747
  if (isProxyHost && (u.pathname.startsWith("/p/") || u.pathname.startsWith("/u/") || SIZED_PROXY_PATH.test(u.pathname))) {
@@ -2414,6 +2449,7 @@ exports.buildSrcSetForFormat = buildSrcSetForFormat;
2414
2449
  exports.catchPostImage = catchPostImage;
2415
2450
  exports.getEntryImageRawUrl = getEntryImageRawUrl;
2416
2451
  exports.isAllowedEmbedSrc = isAllowedEmbedSrc;
2452
+ exports.isLegacySizedProxyUrl = isLegacySizedProxyUrl;
2417
2453
  exports.isPictureEligibleRawUrl = isPictureEligibleRawUrl;
2418
2454
  exports.isValidPermlink = isValidPermlink;
2419
2455
  exports.postBodySummary = getPostBodySummary;