fix(studio): share safe media path cleanup

This commit is contained in:
ukimsanov
2026-07-06 14:35:41 -07:00
parent e0090efbf6
commit 04f96da169
3 changed files with 11 additions and 9 deletions
@@ -22,6 +22,7 @@ import {
} from "../../utils/studioPendingEdits";
import type { DomEditSelection } from "./domEditing";
import { ColorGradingControls } from "./propertyPanelColorGradingControls";
import { stripQueryAndHash } from "./propertyPanelHelpers";
import { Section } from "./propertyPanelPrimitives";
const COLOR_GRADING_DATA_KEY = HF_COLOR_GRADING_ATTR.replace(/^data-/, "");
@@ -55,14 +56,6 @@ interface MediaMetadataResponse {
metadata: MediaMetadata;
}
function stripQueryAndHash(value: string): string {
const queryIndex = value.indexOf("?");
const hashIndex = value.indexOf("#");
if (queryIndex < 0) return hashIndex < 0 ? value : value.slice(0, hashIndex);
if (hashIndex < 0) return value.slice(0, queryIndex);
return value.slice(0, Math.min(queryIndex, hashIndex));
}
function stripPreviewAssetPath(src: string, projectId: string): string | null {
let pathname = src;
try {
@@ -10,6 +10,14 @@ export type {
PropertyPanelProps,
} from "./propertyPanelTypes";
export function stripQueryAndHash(value: string): string {
const queryIndex = value.indexOf("?");
const hashIndex = value.indexOf("#");
if (queryIndex < 0) return hashIndex < 0 ? value : value.slice(0, hashIndex);
if (hashIndex < 0) return value.slice(0, queryIndex);
return value.slice(0, Math.min(queryIndex, hashIndex));
}
/* ------------------------------------------------------------------ */
/* Font types & constants (shared by font and section modules) */
/* ------------------------------------------------------------------ */
@@ -9,6 +9,7 @@ import {
LABEL,
parseNumericValue,
RESPONSIVE_GRID,
stripQueryAndHash,
} from "./propertyPanelHelpers";
import { Section, SegmentedControl, SelectField, SliderControl } from "./propertyPanelPrimitives";
@@ -77,7 +78,7 @@ export function MediaSection({
projectDir && srcAttr && !srcAttr.startsWith("http") ? `${projectDir}/${srcAttr}` : srcAttr;
const projectSrc =
srcAttr && !/^(?:https?:|data:|blob:)/i.test(srcAttr)
? srcAttr.replace(/^\.\//, "").replace(/[?#].*$/, "")
? stripQueryAndHash(srcAttr.startsWith("./") ? srcAttr.slice(2) : srcAttr)
: "";
const canRemoveBackground = Boolean(onRemoveBackground && isVisualMedia && projectSrc);
const panelTitle = isImage ? "Image" : isVideo ? "Video" : "Audio";