refactor: simplify demo media
This commit is contained in:
1 parent
d8eec36d98
commit
245a477965
10 files changed
+14
-98
No files matched your search
@@ -805,7 +805,10 @@ const buildDemoWidgets = (appIds: string[], customWidgetDefinitionId: string): D
|
||||
width: 4,
|
||||
height: 3,
|
||||
needsIntegration: false,
|
||||
options: { embedUrl: "/api/demo-assets/overview", allowScrolling: true },
|
||||
options: {
|
||||
embedUrl: "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/homarr.svg",
|
||||
allowScrolling: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
kind: "video",
|
||||
@@ -815,7 +818,7 @@ const buildDemoWidgets = (appIds: string[], customWidgetDefinitionId: string): D
|
||||
height: 3,
|
||||
needsIntegration: false,
|
||||
options: {
|
||||
feedUrl: "/api/demo-assets/video/file.mp4",
|
||||
feedUrl: "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4",
|
||||
hasAutoPlay: false,
|
||||
isMuted: true,
|
||||
hasControls: true,
|
||||
|
||||
@@ -22,11 +22,6 @@ import type { VpnSummary } from "../interfaces/vpn-summary/vpn-summary-types";
|
||||
|
||||
const demoTimestamp = "2026-08-24T12:00:00.000Z";
|
||||
|
||||
const demoPhoto = (label: string, color: string) => {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800"><defs><linearGradient id="g" x1="0" x2="1" y1="0" y2="1"><stop stop-color="${color}"/><stop offset="1" stop-color="#15121f"/></linearGradient></defs><rect width="1200" height="800" fill="url(#g)"/><circle cx="930" cy="180" r="120" fill="#fff" opacity=".14"/><path d="M0 650L310 350l180 170 190-230 520 510H0z" fill="#fff" opacity=".18"/><text x="70" y="720" fill="#fff" font-size="68" font-family="system-ui" font-weight="700">${label}</text></svg>`;
|
||||
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
||||
};
|
||||
|
||||
const anchorNote: AnchorNote = {
|
||||
id: "homarr-demo-note",
|
||||
title: "Homarr demo runbook",
|
||||
@@ -168,7 +163,7 @@ export const mockWidgetData = {
|
||||
fileCreatedAt: demoTimestamp,
|
||||
updatedAt: demoTimestamp,
|
||||
type: "IMAGE",
|
||||
publicLink: demoPhoto("Paris weekend", "#6f4cff"),
|
||||
publicLink: "https://images.unsplash.com/photo-1502602898657-3e91760cbb34?auto=format&fit=crop&w=1200&q=80",
|
||||
},
|
||||
{
|
||||
id: "demo-photo-2",
|
||||
@@ -177,7 +172,7 @@ export const mockWidgetData = {
|
||||
fileCreatedAt: demoTimestamp,
|
||||
updatedAt: demoTimestamp,
|
||||
type: "IMAGE",
|
||||
publicLink: demoPhoto("Alpine trails", "#198f83"),
|
||||
publicLink: "https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&w=1200&q=80",
|
||||
},
|
||||
],
|
||||
} satisfies ImmichAlbum,
|
||||
|
||||
@@ -18,11 +18,8 @@ describe("iframe policy", () => {
|
||||
expect(getSandboxFlags(permissions)).toContain("allow-modals");
|
||||
});
|
||||
|
||||
it("accepts HTTP URLs and same-origin paths", () => {
|
||||
it("accepts only HTTP protocols", () => {
|
||||
expect(isSupportedProtocol("https://example.com")).toBe(true);
|
||||
expect(isSupportedProtocol("/api/demo-assets/overview")).toBe(true);
|
||||
expect(isSupportedProtocol("//evil.example")).toBe(false);
|
||||
expect(isSupportedProtocol("/\\evil.example")).toBe(false);
|
||||
expect(isSupportedProtocol("javascript:alert(1)")).toBe(false);
|
||||
expect(isSupportedProtocol("not a url")).toBe(false);
|
||||
});
|
||||
|
||||
@@ -7,15 +7,13 @@ import { objectEntries } from "@homarr/common";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { getSafeApplicationUrl } from "../common/application-url";
|
||||
import classes from "./component.module.css";
|
||||
import { getSafeIframeUrl } from "./safe-url";
|
||||
|
||||
export { getSafeIframeUrl } from "./safe-url";
|
||||
|
||||
export default function IFrameWidget({ options, isEditMode }: WidgetComponentProps<"iframe">) {
|
||||
const t = useI18n("widget.iframe");
|
||||
const { embedUrl, allowScrolling, ...permissions } = options;
|
||||
const safeEmbedUrl = getSafeIframeUrl(embedUrl);
|
||||
const safeEmbedUrl = getSafeApplicationUrl(embedUrl);
|
||||
const allowedPermissions = getAllowedPermissions(permissions);
|
||||
const sandboxFlags = getSandboxFlags(permissions);
|
||||
|
||||
@@ -47,7 +45,7 @@ export default function IFrameWidget({ options, isEditMode }: WidgetComponentPro
|
||||
const supportedProtocols = ["http", "https"];
|
||||
|
||||
export const isSupportedProtocol = (url: string) => {
|
||||
return getSafeIframeUrl(url) !== undefined;
|
||||
return getSafeApplicationUrl(url) !== undefined;
|
||||
};
|
||||
|
||||
const NoUrl = () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { IconBrowser, IconExternalLink } from "@tabler/icons-react";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { getSafeApplicationUrl } from "../common/application-url";
|
||||
import { optionsBuilder } from "../options";
|
||||
import { getSafeIframeUrl } from "./safe-url";
|
||||
|
||||
const createOptions = () =>
|
||||
optionsBuilder.from((factory) => ({
|
||||
@@ -23,7 +23,7 @@ export const { definition, componentLoader } = createWidgetDefinition("iframe",
|
||||
supportsAdvancedFocus: false,
|
||||
icon: IconBrowser,
|
||||
contextActions: ({ options }) => {
|
||||
const embedUrl = getSafeIframeUrl(options.embedUrl);
|
||||
const embedUrl = getSafeApplicationUrl(options.embedUrl);
|
||||
return embedUrl
|
||||
? [
|
||||
{
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { getSafeAppHref, getSafeApplicationUrl } from "@homarr/common";
|
||||
|
||||
export const getSafeIframeUrl = (url: unknown) => {
|
||||
const applicationUrl = getSafeApplicationUrl(url);
|
||||
if (applicationUrl) return applicationUrl;
|
||||
|
||||
const relativeUrl = getSafeAppHref(url);
|
||||
if (relativeUrl?.startsWith("/") && !relativeUrl.startsWith("//")) return relativeUrl;
|
||||
return undefined;
|
||||
};
|
||||
Reference in new issue
Block a user