@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.
@@ -60,6 +60,7 @@ declare function catchPostImage(obj: Entry | string, width?: number, height?: nu
60
60
  declare function getPostBodySummary(obj: Entry | string, length?: number, platform?: 'ios' | 'android' | 'web'): string;
61
61
 
62
62
  declare function setProxyBase(p: string): void;
63
+ declare function isLegacySizedProxyUrl(url?: string): boolean;
63
64
  interface ProxifyOptions {
64
65
  /**
65
66
  * Request a tiny blurred LQIP placeholder. The proxy resizes to ~20px and
@@ -159,4 +160,4 @@ declare function isValidPermlink(permlink: string): boolean;
159
160
  */
160
161
  declare function simpleMarkdownToHTML(input: string): string;
161
162
 
162
- export { type Entry, IMAGE_SIZES, type ProxifyOptions, type RenderOptions, SECTION_LIST, type SeoContext, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
163
+ export { type Entry, IMAGE_SIZES, type ProxifyOptions, type RenderOptions, SECTION_LIST, type SeoContext, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
@@ -601,6 +601,40 @@ function isValidUrl(url) {
601
601
  return false;
602
602
  }
603
603
  }
604
+ var MAX_PROXIED_URL_LENGTH = 2048;
605
+ var LEGACY_SIZED_PROXY_RE = /^https:\/\/(?:images\.hive\.blog|steemitimages\.com)\/\d+x\d+\/(.+)$/;
606
+ function isLegacySizedProxyUrl(url) {
607
+ if (!url || typeof url !== "string") return false;
608
+ return LEGACY_SIZED_PROXY_RE.test(url);
609
+ }
610
+ function extractLegacySizedSource(url) {
611
+ const m = LEGACY_SIZED_PROXY_RE.exec(url);
612
+ if (!m) return null;
613
+ const rest = m[1];
614
+ const hashIndex = rest.indexOf("#");
615
+ const addressable = hashIndex >= 0 ? rest.slice(0, hashIndex) : rest;
616
+ const qIndex = addressable.indexOf("?");
617
+ const path = qIndex >= 0 ? addressable.slice(0, qIndex) : addressable;
618
+ const query = qIndex >= 0 ? addressable.slice(qIndex + 1) : "";
619
+ let end = path.length;
620
+ while (end > 0 && path.charCodeAt(end - 1) === 47) {
621
+ end--;
622
+ }
623
+ try {
624
+ const inner = new URL(path.slice(0, end));
625
+ if (query) {
626
+ for (const [key, value] of new URLSearchParams(query)) {
627
+ inner.searchParams.append(key, value);
628
+ }
629
+ }
630
+ return inner.toString();
631
+ } catch {
632
+ return null;
633
+ }
634
+ }
635
+ function isLegacyForeignProxyUrl(url) {
636
+ 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;
637
+ }
604
638
  function getLatestUrl(str) {
605
639
  const [last] = [...str.replace(/https?:\/\//g, "\n$&").trim().split("\n")].reverse();
606
640
  return last;
@@ -609,17 +643,17 @@ function proxifyForFormat(url, width = 0, height = 0, format = "match", opts = {
609
643
  if (!url || typeof url !== "string" || !isValidUrl(url)) {
610
644
  return "";
611
645
  }
612
- const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
613
- if (url.indexOf("https://images.hive.blog/") === 0 && url.indexOf("https://images.hive.blog/D") !== 0) {
614
- return url.replace("https://images.hive.blog", proxyBase);
646
+ if (url.length > MAX_PROXIED_URL_LENGTH) {
647
+ return "";
615
648
  }
616
- if (url.indexOf("https://steemitimages.com/") === 0 && url.indexOf("https://steemitimages.com/D") !== 0) {
617
- return url.replace("https://steemitimages.com", proxyBase);
649
+ const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
650
+ if (isLegacyForeignProxyUrl(url) && !(isLegacySizedProxyUrl(url) && routeThroughProxy)) {
651
+ return url.replace("https://images.hive.blog", proxyBase).replace("https://steemitimages.com", proxyBase);
618
652
  }
619
653
  if (url.indexOf("https://images.ecency.com/") === 0 && !routeThroughProxy) {
620
654
  return url.replace("https://images.ecency.com", proxyBase);
621
655
  }
622
- const realUrl = getLatestUrl(url);
656
+ const realUrl = extractLegacySizedSource(url) ?? getLatestUrl(url);
623
657
  const pHash = extractPHash(realUrl);
624
658
  const options = {
625
659
  format,
@@ -679,6 +713,7 @@ function isPictureEligibleRawUrl(rawUrl) {
679
713
  return false;
680
714
  }
681
715
  if (u.protocol !== "http:" && u.protocol !== "https:") return false;
716
+ if (isLegacySizedProxyUrl(rawUrl)) return true;
682
717
  const host = `${u.protocol}//${u.host}`;
683
718
  const isProxyHost = host === proxyBase || host === "https://images.ecency.com";
684
719
  if (isProxyHost && (u.pathname.startsWith("/p/") || u.pathname.startsWith("/u/") || SIZED_PROXY_PATH.test(u.pathname))) {
@@ -2378,6 +2413,6 @@ function getPostBodySummary(obj, length, platform) {
2378
2413
  return res;
2379
2414
  }
2380
2415
 
2381
- export { IMAGE_SIZES, SECTION_LIST, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
2416
+ export { IMAGE_SIZES, SECTION_LIST, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
2382
2417
  //# sourceMappingURL=index.js.map
2383
2418
  //# sourceMappingURL=index.js.map