@devvit/ui-renderer 0.10.4-next-2023-08-17-9b84b2677.0 → 0.10.4-next-2023-08-17-d35139fd0.0
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/blocks/templates/constants.d.ts +7 -0
- package/blocks/templates/constants.d.ts.map +1 -0
- package/blocks/templates/constants.js +7 -0
- package/blocks/templates/renderImageBlock.d.ts.map +1 -1
- package/blocks/templates/renderImageBlock.js +10 -2
- package/blocks/templates/util.d.ts +1 -0
- package/blocks/templates/util.d.ts.map +1 -1
- package/blocks/templates/util.js +13 -0
- package/blocks/templates/util.test.d.ts.map +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const REDD_IT = "redd.it";
|
|
2
|
+
export declare const REDDIT_STATIC = "redditstatic.com";
|
|
3
|
+
export declare const REDDIT_MEDIA = "redditmedia.com";
|
|
4
|
+
export declare const SNOO_DEV = "snoo.dev";
|
|
5
|
+
export declare const VerifiedPublicImageHosts: string[];
|
|
6
|
+
export declare const VerifiedImageHosts: string[];
|
|
7
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAChD,eAAO,MAAM,YAAY,oBAAoB,CAAC;AAC9C,eAAO,MAAM,QAAQ,aAAa,CAAC;AAEnC,eAAO,MAAM,wBAAwB,UAAyC,CAAC;AAC/E,eAAO,MAAM,kBAAkB,UAAmD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Only the following domains are approved: redd.it, redditstatic.com, redditmedia.com, or snoo.dev
|
|
2
|
+
export const REDD_IT = 'redd.it';
|
|
3
|
+
export const REDDIT_STATIC = 'redditstatic.com';
|
|
4
|
+
export const REDDIT_MEDIA = 'redditmedia.com';
|
|
5
|
+
export const SNOO_DEV = 'snoo.dev';
|
|
6
|
+
export const VerifiedPublicImageHosts = [REDD_IT, REDDIT_STATIC, REDDIT_MEDIA];
|
|
7
|
+
export const VerifiedImageHosts = [SNOO_DEV, REDD_IT, REDDIT_STATIC, REDDIT_MEDIA];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"renderImageBlock.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/renderImageBlock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAWvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAA6B,YAAY,EAAE,MAAM,WAAW,CAAC;AAKpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,GAAG,YAAY,CA4C/E"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { nothing } from 'lit';
|
|
2
2
|
import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
|
|
3
3
|
import { cursorClass, defaultClasses, onClickAction, resizeModeClass, sizingClass, sizingStyle, stackChildClass, } from '../attributes.js';
|
|
4
|
-
import { classMap } from './util.js';
|
|
4
|
+
import { classMap, isValidImageURL } from './util.js';
|
|
5
|
+
import { VerifiedPublicImageHosts } from './constants.js';
|
|
6
|
+
const FALLBACK_IMG_URL = 'https://i.redd.it/p1vmc5ulmpib1.png';
|
|
5
7
|
export function renderImageBlock(block, ctx) {
|
|
6
8
|
const { html, styleMap, ifDefined } = getTemplateRenderingStrategy();
|
|
7
9
|
if (!block.config?.imageConfig) {
|
|
@@ -9,6 +11,12 @@ export function renderImageBlock(block, ctx) {
|
|
|
9
11
|
return nothing;
|
|
10
12
|
}
|
|
11
13
|
const { width, height, url, description, resizeMode } = block.config.imageConfig;
|
|
14
|
+
let imageUrl = url;
|
|
15
|
+
if (!isValidImageURL(imageUrl)) {
|
|
16
|
+
console.error(`Invalid image URL: Image URL domain must be one of ${VerifiedPublicImageHosts.join(', ')}.`);
|
|
17
|
+
// Replace url with a fallback snoo
|
|
18
|
+
imageUrl = FALLBACK_IMG_URL;
|
|
19
|
+
}
|
|
12
20
|
const classes = {
|
|
13
21
|
...defaultClasses(block.type),
|
|
14
22
|
...stackChildClass(ctx.stackDirection),
|
|
@@ -22,7 +30,7 @@ export function renderImageBlock(block, ctx) {
|
|
|
22
30
|
const onClick = onClickAction(block, ctx);
|
|
23
31
|
return html `
|
|
24
32
|
<img
|
|
25
|
-
src="${
|
|
33
|
+
src="${imageUrl}"
|
|
26
34
|
width="${width}"
|
|
27
35
|
height="${height}"
|
|
28
36
|
alt="${description}"
|
|
@@ -11,4 +11,5 @@ export declare function ref(ref: RefOrCallback): ReturnType<typeof clientRef> |
|
|
|
11
11
|
export declare function isHTMLElement(el: HTMLElement | Element | undefined): el is HTMLElement;
|
|
12
12
|
export declare function resolveIcon(name: string): TemplateResult;
|
|
13
13
|
export declare function sanitizeStyleInfo(styleInfo: StyleInfo): StyleInfo;
|
|
14
|
+
export declare function isValidImageURL(imageUrl: string): boolean;
|
|
14
15
|
//# sourceMappingURL=util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,cAAc,EAAE,M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gB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAYxD;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAOjE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAWzD"}
|
package/blocks/templates/util.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ref as clientRef } from 'lit/directives/ref.js';
|
|
|
4
4
|
import { unsafeHTML as serverUnsafeHTML } from '@reddit/baseplate/html.js';
|
|
5
5
|
import { getTemplateRenderingStrategy } from '@reddit/faceplate-ui/faceplateUIConfig.js';
|
|
6
6
|
import faceplateIcons from '@reddit/faceplate-ui/svgs/svg-manifest.js';
|
|
7
|
+
import { VerifiedImageHosts, REDD_IT } from './constants.js';
|
|
7
8
|
export function classMap(classInfo, forceString) {
|
|
8
9
|
const { getType } = getTemplateRenderingStrategy();
|
|
9
10
|
if (getType() === 'client' && forceString !== true) {
|
|
@@ -53,3 +54,15 @@ export function sanitizeStyleInfo(styleInfo) {
|
|
|
53
54
|
}
|
|
54
55
|
return styleInfo;
|
|
55
56
|
}
|
|
57
|
+
export function isValidImageURL(imageUrl) {
|
|
58
|
+
try {
|
|
59
|
+
// The second "base" param helps to handle relative paths to local files
|
|
60
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#parameters
|
|
61
|
+
const hostName = new URL(imageUrl, `https://i.${REDD_IT}`)?.hostname;
|
|
62
|
+
const tld = hostName.split('.').slice(-2).join('.');
|
|
63
|
+
return Boolean(tld) && VerifiedImageHosts.includes(tld);
|
|
64
|
+
}
|
|
65
|
+
catch (_) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.test.d.ts","sourceRoot":"","sources":["../../../library/src/blocks/templates/util.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/ui-renderer",
|
|
3
|
-
"version": "0.10.4-next-2023-08-17-
|
|
3
|
+
"version": "0.10.4-next-2023-08-17-d35139fd0.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
},
|
|
48
48
|
"types": "./index.d.ts",
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@devvit/protos": "0.10.4-next-2023-08-17-
|
|
51
|
-
"@devvit/runtime-lite": "0.10.4-next-2023-08-17-
|
|
52
|
-
"@devvit/runtimes": "0.10.4-next-2023-08-17-
|
|
50
|
+
"@devvit/protos": "0.10.4-next-2023-08-17-d35139fd0.0",
|
|
51
|
+
"@devvit/runtime-lite": "0.10.4-next-2023-08-17-d35139fd0.0",
|
|
52
|
+
"@devvit/runtimes": "0.10.4-next-2023-08-17-d35139fd0.0",
|
|
53
53
|
"@lottiefiles/lottie-player": "1.7.1",
|
|
54
54
|
"p-queue": "7.3.4",
|
|
55
55
|
"rxjs": "7.5.7"
|
|
@@ -76,8 +76,9 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@devvit/eslint-config": "0.10.3",
|
|
78
78
|
"@devvit/repo-tools": "0.10.3",
|
|
79
|
-
"@devvit/tsconfig": "0.10.4-next-2023-08-17-
|
|
79
|
+
"@devvit/tsconfig": "0.10.4-next-2023-08-17-d35139fd0.0",
|
|
80
80
|
"@lit/localize": "0.11.4",
|
|
81
|
+
"@open-wc/testing-helpers": "2.3.0",
|
|
81
82
|
"@reddit/baseplate": "0.14.0",
|
|
82
83
|
"@reddit/eslint-plugin-i18n-shreddit": "0.1.0",
|
|
83
84
|
"autoprefixer": "10.4.14",
|
|
@@ -100,5 +101,5 @@
|
|
|
100
101
|
"directory": "dist"
|
|
101
102
|
},
|
|
102
103
|
"source": "./src/index.ts",
|
|
103
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "fae26013e749605facd524c6ad005006dcf0af85"
|
|
104
105
|
}
|