@ecency/render-helper 2.5.35 → 2.5.37

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.
@@ -156,10 +156,10 @@ declare function buildSrcSetForFormat(url?: string, format?: 'avif' | 'webp' | '
156
156
  * Whether a RAW (pre-proxify) image URL is safe to offer avif/webp `<source>`
157
157
  * renditions for. Requires an http(s) URL whose PATHNAME ends in a static-raster
158
158
  * extension and that is NOT already proxified — already-proxified routes (`/p/`
159
- * base58 hash, `/u/` avatars, `WxH` sized) have the original extension stripped,
160
- * so we can't prove the underlying bytes aren't an animated gif and must fall
161
- * back to a bare img. URL parsing (not string regex on the host) keeps the host
162
- * comparison exact and avoids an interpolated-hostname regex.
159
+ * base58 hash, `/u/` avatars) have the original extension stripped, so we can't
160
+ * prove the underlying bytes aren't an animated gif and must fall back to a bare
161
+ * img. URL parsing (not string regex on the host) keeps the host comparison
162
+ * exact and avoids an interpolated-hostname regex.
163
163
  */
164
164
  declare function isPictureEligibleRawUrl(rawUrl?: string): boolean;
165
165
  /**
@@ -716,6 +716,9 @@ function buildSrcSetForFormat(url, format = "match") {
716
716
  var STATIC_RASTER_PATH_EXT = /\.(?:jpe?g|png|webp)$/i;
717
717
  var SIZED_PROXY_PATH = /^\/\d+x\d+\//;
718
718
  function isPictureEligibleRawUrl(rawUrl) {
719
+ return isPictureEligible(rawUrl, true);
720
+ }
721
+ function isPictureEligible(rawUrl, mayUnwrapLegacy) {
719
722
  if (!rawUrl || typeof rawUrl !== "string") return false;
720
723
  let u;
721
724
  try {
@@ -724,7 +727,10 @@ function isPictureEligibleRawUrl(rawUrl) {
724
727
  return false;
725
728
  }
726
729
  if (u.protocol !== "http:" && u.protocol !== "https:") return false;
727
- if (isLegacySizedProxyUrl(rawUrl)) return true;
730
+ if (mayUnwrapLegacy && isLegacySizedProxyUrl(rawUrl)) {
731
+ const nested = extractLegacySizedSource(rawUrl);
732
+ return nested !== null && isPictureEligible(nested, false);
733
+ }
728
734
  const host = `${u.protocol}//${u.host}`;
729
735
  const isProxyHost = host === proxyBase || host === "https://images.ecency.com";
730
736
  if (isProxyHost && (u.pathname.startsWith("/p/") || u.pathname.startsWith("/u/") || SIZED_PROXY_PATH.test(u.pathname))) {
@@ -2210,10 +2216,6 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
2210
2216
  }
2211
2217
 
2212
2218
  // src/catch-post-image.ts
2213
- var gifLinkRegex = /\.(gif)$/i;
2214
- function isGifLink(link) {
2215
- return gifLinkRegex.test(link);
2216
- }
2217
2219
  var BACKTICK_FENCE_RE = /```[\s\S]*?```/g;
2218
2220
  var TILDE_FENCE_RE = /~~~[\s\S]*?~~~/g;
2219
2221
  var INLINE_CODE_RE = /`[^`\n]*`/g;
@@ -2718,11 +2720,7 @@ function firstMetaUrl(value) {
2718
2720
  return void 0;
2719
2721
  }
2720
2722
  function proxifyFound(src, width, height, format) {
2721
- const decoded = decodeEntities(src);
2722
- if (isGifLink(decoded)) {
2723
- return proxifyImageSrc(decoded, 0, 0, format);
2724
- }
2725
- return proxifyImageSrc(decoded, width, height, format);
2723
+ return proxifyImageSrc(decodeEntities(src), width, height, format);
2726
2724
  }
2727
2725
  function getImage(entry, width = 0, height = 0, format = "match", fastMode = false) {
2728
2726
  let meta;
@@ -2737,29 +2735,17 @@ function getImage(entry, width = 0, height = 0, format = "match", fastMode = fal
2737
2735
  }
2738
2736
  const thumbnail = firstMetaUrl(meta?.thumbnails);
2739
2737
  if (thumbnail) {
2740
- const decodedThumbnail = decodeEntities(thumbnail);
2741
- const proxied = isGifLink(decodedThumbnail) ? proxifyImageSrc(decodedThumbnail, 0, 0, format) : proxifyImageSrc(decodedThumbnail, width, height, format);
2738
+ const proxied = proxifyImageSrc(decodeEntities(thumbnail), width, height, format);
2742
2739
  if (proxied) {
2743
2740
  return proxied;
2744
2741
  }
2745
2742
  }
2746
2743
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
2747
- const decodedImage = decodeEntities(meta.image);
2748
- if (isGifLink(decodedImage)) {
2749
- return proxifyImageSrc(decodedImage, 0, 0, format);
2750
- }
2751
- return proxifyImageSrc(decodedImage, width, height, format);
2744
+ return proxifyImageSrc(decodeEntities(meta.image), width, height, format);
2752
2745
  }
2753
2746
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
2754
2747
  if (typeof meta.image[0] === "string") {
2755
- const decodedImage = decodeEntities(meta.image[0]);
2756
- if (isGifLink(decodedImage)) {
2757
- return proxifyImageSrc(decodedImage, 0, 0, format);
2758
- }
2759
- return proxifyImageSrc(decodedImage, width, height, format);
2760
- }
2761
- if (isGifLink(meta.image[0])) {
2762
- return proxifyImageSrc(meta.image[0], 0, 0, format);
2748
+ return proxifyImageSrc(decodeEntities(meta.image[0]), width, height, format);
2763
2749
  }
2764
2750
  return proxifyImageSrc(meta.image[0], width, height, format);
2765
2751
  }