@ecency/render-helper 2.5.6 → 2.5.8
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.
- package/dist/browser/index.d.ts +18 -2
- package/dist/browser/index.js +20 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +20 -6
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +20 -6
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -106,6 +106,7 @@ var TRUVVL_REGEX = /^https?:\/\/embed.truvvl.com\/(@[\w.\d-]+)\/(.*)/i;
|
|
|
106
106
|
var LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/[^?#]+(?:$|[?#])/i;
|
|
107
107
|
var ODYSEE_REGEX = /^(https?:)?\/\/odysee\.com\/(?:\$|%24)\/embed\/[^?#]+(?:$|[?#])/i;
|
|
108
108
|
var SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i;
|
|
109
|
+
var SKATEHYPE_EMBED_REGEX = /^(https?:)?\/\/(www\.)?skatehype\.com\/ifplay\.php\?v=\d+(?:$|[&#])/i;
|
|
109
110
|
var ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/[^/?#]+(?:$|[?#])/i;
|
|
110
111
|
var SPEAK_REGEX = /(?:https?:\/\/(?:(?:play\.)?3speak\.([a-z]+)\/watch\?v=)|(?:(?:play\.)?3speak\.([a-z]+)\/embed\?v=))([A-Za-z0-9_\-\.\/]+)(&.*)?/i;
|
|
111
112
|
var SPEAK_EMBED_REGEX = /^(https?:)?\/\/(?:play\.)?3speak\.([a-z]+)\/(?:embed|watch)\?.+$/i;
|
|
@@ -503,9 +504,11 @@ function setProxyBase(p2) {
|
|
|
503
504
|
function getProxyBase() {
|
|
504
505
|
return proxyBase;
|
|
505
506
|
}
|
|
507
|
+
var PROXY_P_PREFIXES = () => [`${proxyBase}/p/`, "https://images.ecency.com/p/"];
|
|
506
508
|
function extractPHash(url) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
+
const prefix = PROXY_P_PREFIXES().find((p2) => url.startsWith(p2));
|
|
510
|
+
if (prefix) {
|
|
511
|
+
const [hash] = url.slice(prefix.length).split("?");
|
|
509
512
|
return hash.replace(/\.(webp|png)$/, "");
|
|
510
513
|
}
|
|
511
514
|
return null;
|
|
@@ -521,17 +524,18 @@ function getLatestUrl(str) {
|
|
|
521
524
|
const [last] = [...str.replace(/https?:\/\//g, "\n$&").trim().split("\n")].reverse();
|
|
522
525
|
return last;
|
|
523
526
|
}
|
|
524
|
-
function proxifyImageSrc(url, width = 0, height = 0, _format = "match") {
|
|
527
|
+
function proxifyImageSrc(url, width = 0, height = 0, _format = "match", opts = {}) {
|
|
525
528
|
if (!url || typeof url !== "string" || !isValidUrl(url)) {
|
|
526
529
|
return "";
|
|
527
530
|
}
|
|
531
|
+
const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
|
|
528
532
|
if (url.indexOf("https://images.hive.blog/") === 0 && url.indexOf("https://images.hive.blog/D") !== 0) {
|
|
529
533
|
return url.replace("https://images.hive.blog", proxyBase);
|
|
530
534
|
}
|
|
531
535
|
if (url.indexOf("https://steemitimages.com/") === 0 && url.indexOf("https://steemitimages.com/D") !== 0) {
|
|
532
536
|
return url.replace("https://steemitimages.com", proxyBase);
|
|
533
537
|
}
|
|
534
|
-
if (url.indexOf("https://images.ecency.com/") === 0) {
|
|
538
|
+
if (url.indexOf("https://images.ecency.com/") === 0 && !routeThroughProxy) {
|
|
535
539
|
return url.replace("https://images.ecency.com", proxyBase);
|
|
536
540
|
}
|
|
537
541
|
const realUrl = getLatestUrl(url);
|
|
@@ -546,6 +550,9 @@ function proxifyImageSrc(url, width = 0, height = 0, _format = "match") {
|
|
|
546
550
|
if (height > 0) {
|
|
547
551
|
options.height = height;
|
|
548
552
|
}
|
|
553
|
+
if (opts.blur) {
|
|
554
|
+
options.blur = 1;
|
|
555
|
+
}
|
|
549
556
|
const qs = querystring__default.default.stringify(options);
|
|
550
557
|
if (pHash) {
|
|
551
558
|
return `${proxyBase}/p/${pHash}?${qs}`;
|
|
@@ -606,7 +613,7 @@ function img(el, state) {
|
|
|
606
613
|
const base = trimTrailingSlash(getProxyBase());
|
|
607
614
|
const hasAlreadyProxied = src.startsWith(`${base}/p/`) || src.startsWith(`${base}/u/`) || new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/\\d+x\\d+/`).test(src);
|
|
608
615
|
if (shouldReplace && !hasAlreadyProxied) {
|
|
609
|
-
const proxified = proxifyImageSrc(decodedSrc);
|
|
616
|
+
const proxified = proxifyImageSrc(decodedSrc, 0, 0, "match", { forceProxy: true });
|
|
610
617
|
if (proxified) {
|
|
611
618
|
el.setAttribute("src", proxified);
|
|
612
619
|
const srcset = buildSrcSet(decodedSrc);
|
|
@@ -626,7 +633,7 @@ function img(el, state) {
|
|
|
626
633
|
}
|
|
627
634
|
}
|
|
628
635
|
function createImageHTML(src, isLCP) {
|
|
629
|
-
const proxified = proxifyImageSrc(src);
|
|
636
|
+
const proxified = proxifyImageSrc(src, 0, 0, "match", { forceProxy: true });
|
|
630
637
|
if (!proxified) return "";
|
|
631
638
|
const base = trimTrailingSlash(getProxyBase());
|
|
632
639
|
const isAlreadyProxied = src.startsWith(`${base}/u/`) || new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/\\d+x\\d+/`).test(src);
|
|
@@ -1425,6 +1432,13 @@ function iframe(el, parentDomain = "ecency.com", forApp = false) {
|
|
|
1425
1432
|
el.setAttribute("allowfullscreen", "true");
|
|
1426
1433
|
return;
|
|
1427
1434
|
}
|
|
1435
|
+
if (src.match(SKATEHYPE_EMBED_REGEX)) {
|
|
1436
|
+
const normalizedSrc = src.replace(/^(https?:)?\/\//i, "https://");
|
|
1437
|
+
el.setAttribute("src", normalizedSrc);
|
|
1438
|
+
el.setAttribute("frameborder", "0");
|
|
1439
|
+
el.setAttribute("allowfullscreen", "true");
|
|
1440
|
+
return;
|
|
1441
|
+
}
|
|
1428
1442
|
if (src.match(ARCH_REGEX)) {
|
|
1429
1443
|
el.setAttribute("src", src);
|
|
1430
1444
|
return;
|