sdk: broaden legacy iframe/video import heuristics

This commit is contained in:
clawdbot 2026-01-27 23:53:33 +08:00
parent decf2d61af
commit 704e29a6d8
3 changed files with 42 additions and 2 deletions

View File

@ -158,6 +158,9 @@ function looksLikeIframeOption(option: unknown): boolean {
if (typeof option === 'object') {
const o = option as Record<string, unknown>;
if ('iframeUrl' in o || 'iframeSrc' in o || 'embedUrl' in o) return true;
// Some exports store raw HTML instead of a URL.
if ('html' in o || 'htmlContent' in o || 'content' in o || 'template' in o) return true;
}
const url = pickUrlLike(option);
@ -181,7 +184,19 @@ function looksLikeVideoOption(option: unknown): boolean {
// Prefer explicit video-ish keys when option is an object.
if (typeof option === 'object') {
const o = option as Record<string, unknown>;
if ('videoUrl' in o || 'videoSrc' in o || 'mp4' in o || 'm3u8' in o || 'flv' in o || 'hls' in o || 'rtsp' in o) {
if (
'videoUrl' in o ||
'videoSrc' in o ||
'mp4' in o ||
'm3u8' in o ||
'flv' in o ||
'hls' in o ||
'rtsp' in o ||
// list-ish shapes
'sources' in o ||
'sourceList' in o ||
'urlList' in o
) {
return true;
}
}

View File

@ -17,9 +17,29 @@ export interface GoViewIframeOption {
*/
export type LegacyIframeOption = GoViewIframeOption;
function toDataHtmlUrl(html: string): string {
// Keep this simple and safe: use a data URL so we can render the provided HTML
// without needing an external host.
// NOTE: encodeURIComponent is important to preserve characters + avoid breaking the URL.
return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
}
function pickSrc(option: GoViewIframeOption): string {
// Prefer the whole option first (covers iframeUrl/embedUrl variants directly on the object).
return pickUrlLike(option) || pickUrlLike(option.dataset) || pickUrlLike(option.src) || pickUrlLike(option.url);
const url = pickUrlLike(option) || pickUrlLike(option.dataset) || pickUrlLike(option.src) || pickUrlLike(option.url);
if (url) return url;
// Some goView / low-code exports store raw HTML instead of a URL.
const html = pickFromNested(
option,
(obj) => {
const v = obj.html ?? obj.htmlContent ?? obj.content ?? obj.template;
return typeof v === 'string' ? v : undefined;
},
2,
);
return html ? toDataHtmlUrl(html) : '';
}
function toMaybeNumber(v: unknown): number | undefined {

View File

@ -34,6 +34,7 @@ function pickUrlLikeInner(input: unknown, depth: number): string {
for (const key of [
'value',
'url',
'uri',
'src',
'href',
'link',
@ -86,6 +87,10 @@ function pickUrlLikeInner(input: unknown, depth: number): string {
'props',
'source',
'media',
// common list-ish wrappers for media sources
'sources',
'sourceList',
'urlList',
// widget-ish wrappers seen in exports
'iframe',
'video',