feat(sdk): improve legacy iframe/video import detection
This commit is contained in:
parent
5d6aae77ef
commit
f96f77ad9c
@ -11,6 +11,7 @@ import { convertGoViewImageOptionToNodeProps, type GoViewImageOption } from '../
|
||||
import { convertGoViewIframeOptionToNodeProps, type GoViewIframeOption } from '../widgets/iframe';
|
||||
import { convertGoViewVideoOptionToNodeProps, type GoViewVideoOption } from '../widgets/video';
|
||||
import { convertGoViewTextOptionToNodeProps, type GoViewTextOption } from '../widgets/text';
|
||||
import { pickUrlLike } from '../widgets/urlLike';
|
||||
|
||||
export interface GoViewComponentLike {
|
||||
id?: string;
|
||||
@ -117,6 +118,38 @@ function isVideo(c: GoViewComponentLike): boolean {
|
||||
return k.includes('mp4') || k.includes('media') || k.includes('player') || k.includes('stream');
|
||||
}
|
||||
|
||||
function looksLikeIframeOption(option: unknown): boolean {
|
||||
if (!option || typeof option !== 'object') return false;
|
||||
const o = option as Record<string, unknown>;
|
||||
|
||||
// Prefer explicit iframe-ish keys.
|
||||
if ('iframeUrl' in o || 'iframeSrc' in o || 'embedUrl' in o) return true;
|
||||
|
||||
const url = pickUrlLike(option);
|
||||
if (!url) return false;
|
||||
|
||||
// If it isn't an obvious media URL, it's often an iframe/embed.
|
||||
// (We deliberately keep this conservative; image/video are handled earlier.)
|
||||
return /^https?:\/\//i.test(url) && !/\.(mp4|m3u8|flv)(\?|#|$)/i.test(url);
|
||||
}
|
||||
|
||||
function looksLikeVideoOption(option: unknown): boolean {
|
||||
if (!option || typeof option !== 'object') return false;
|
||||
const o = option as Record<string, unknown>;
|
||||
|
||||
// Prefer explicit video-ish keys.
|
||||
if ('videoUrl' in o || 'videoSrc' in o || 'mp4' in o || 'm3u8' in o || 'flv' in o || 'hls' in o || 'rtsp' in o) return true;
|
||||
|
||||
const url = pickUrlLike(option);
|
||||
if (!url) return false;
|
||||
|
||||
// Common direct URL patterns.
|
||||
if (/\.(mp4|m3u8|flv)(\?|#|$)/i.test(url)) return true;
|
||||
if (/\bm3u8\b/i.test(url)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function pick<T>(...values: Array<T | undefined | null>): T | undefined {
|
||||
for (const v of values) {
|
||||
if (v !== undefined && v !== null) return v as T;
|
||||
@ -237,8 +270,10 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isIframe(c)) {
|
||||
const props = convertGoViewIframeOptionToNodeProps(optionOf(c) as GoViewIframeOption);
|
||||
const option = optionOf(c);
|
||||
|
||||
if (isIframe(c) || looksLikeIframeOption(option)) {
|
||||
const props = convertGoViewIframeOptionToNodeProps(option as GoViewIframeOption);
|
||||
nodes.push({
|
||||
id: c.id ?? `import_iframe_${Math.random().toString(16).slice(2)}`,
|
||||
type: 'iframe',
|
||||
@ -251,8 +286,8 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isVideo(c)) {
|
||||
const props = convertGoViewVideoOptionToNodeProps(optionOf(c) as GoViewVideoOption);
|
||||
if (isVideo(c) || looksLikeVideoOption(option)) {
|
||||
const props = convertGoViewVideoOptionToNodeProps(option as GoViewVideoOption);
|
||||
nodes.push({
|
||||
id: c.id ?? `import_video_${Math.random().toString(16).slice(2)}`,
|
||||
type: 'video',
|
||||
|
||||
@ -50,6 +50,13 @@ function pickUrlLikeInner(input: unknown, depth: number): string {
|
||||
'mp4',
|
||||
'm3u8',
|
||||
'flv',
|
||||
// other streaming-ish keys
|
||||
'hls',
|
||||
'hlsUrl',
|
||||
'stream',
|
||||
'streamUrl',
|
||||
'rtsp',
|
||||
'rtspUrl',
|
||||
]) {
|
||||
const v = obj[key];
|
||||
if (typeof v === 'string' && v) return v;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user