sdk: broaden goView iframe/video import heuristics
This commit is contained in:
parent
4e7bf37fdd
commit
91744b4daf
@ -342,7 +342,29 @@ function looksLikeIframeOption(option: unknown): boolean {
|
|||||||
if (containsVideoHtmlDeep(option, 2)) return false;
|
if (containsVideoHtmlDeep(option, 2)) return false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hasAnyKeyDeep(option, ['iframeUrl', 'iframeSrc', 'embedUrl', 'frameUrl', 'frameSrc'], 3) ||
|
hasAnyKeyDeep(
|
||||||
|
option,
|
||||||
|
[
|
||||||
|
'iframeUrl',
|
||||||
|
'iframeSrc',
|
||||||
|
'embedUrl',
|
||||||
|
'frameUrl',
|
||||||
|
'frameSrc',
|
||||||
|
'webUrl',
|
||||||
|
'webpageUrl',
|
||||||
|
'pageUrl',
|
||||||
|
'h5Url',
|
||||||
|
'link',
|
||||||
|
'href',
|
||||||
|
// list-ish
|
||||||
|
'sources',
|
||||||
|
'sourceList',
|
||||||
|
'urlList',
|
||||||
|
'srcList',
|
||||||
|
'iframeList',
|
||||||
|
],
|
||||||
|
3,
|
||||||
|
) ||
|
||||||
// Some exports store raw HTML instead of a URL.
|
// Some exports store raw HTML instead of a URL.
|
||||||
hasAnyKeyDeep(
|
hasAnyKeyDeep(
|
||||||
option,
|
option,
|
||||||
@ -385,7 +407,8 @@ function looksLikeIframeOption(option: unknown): boolean {
|
|||||||
// Avoid misclassifying video streams as iframes.
|
// Avoid misclassifying video streams as iframes.
|
||||||
!/\.(mp4|m3u8|flv|webm|mov|m4v|ogv)(\?|#|$)/i.test(url) &&
|
!/\.(mp4|m3u8|flv|webm|mov|m4v|ogv)(\?|#|$)/i.test(url) &&
|
||||||
!/\bm3u8\b/i.test(url) &&
|
!/\bm3u8\b/i.test(url) &&
|
||||||
!/^(rtsp|rtmp):\/\//i.test(url)
|
!/^(rtsp|rtmp|webrtc|srt):\/\//i.test(url) &&
|
||||||
|
!/^wss?:\/\//i.test(url)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,6 +448,11 @@ function looksLikeVideoOption(option: unknown): boolean {
|
|||||||
'hlsUrl',
|
'hlsUrl',
|
||||||
'flvUrl',
|
'flvUrl',
|
||||||
'm3u8Url',
|
'm3u8Url',
|
||||||
|
'webrtcUrl',
|
||||||
|
'rtcUrl',
|
||||||
|
'wsUrl',
|
||||||
|
'srtUrl',
|
||||||
|
'dashUrl',
|
||||||
'cameraUrl',
|
'cameraUrl',
|
||||||
'cctvUrl',
|
'cctvUrl',
|
||||||
'monitorUrl',
|
'monitorUrl',
|
||||||
@ -471,7 +499,9 @@ function looksLikeVideoOption(option: unknown): boolean {
|
|||||||
if (/\bm3u8\b/i.test(url)) return true;
|
if (/\bm3u8\b/i.test(url)) return true;
|
||||||
|
|
||||||
// Streaming-ish protocols (seen in CCTV/camera widgets).
|
// Streaming-ish protocols (seen in CCTV/camera widgets).
|
||||||
if (/^(rtsp|rtmp):\/\//i.test(url)) return true;
|
if (/^(rtsp|rtmp|webrtc|srt):\/\//i.test(url)) return true;
|
||||||
|
// WebSocket-based stream relays.
|
||||||
|
if (/^wss?:\/\//i.test(url)) return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -501,7 +531,7 @@ function looksLikeJsonString(input: string): boolean {
|
|||||||
const s = input.trim();
|
const s = input.trim();
|
||||||
if (!s) return false;
|
if (!s) return false;
|
||||||
// Avoid parsing obvious URLs.
|
// Avoid parsing obvious URLs.
|
||||||
if (/^(https?:\/\/|\/\/|data:|rtsp:\/\/|rtmp:\/\/)/i.test(s)) return false;
|
if (/^(https?:\/\/|\/\/|data:|rtsp:\/\/|rtmp:\/\/|webrtc:\/\/|srt:\/\/|wss?:\/\/)/i.test(s)) return false;
|
||||||
return (
|
return (
|
||||||
(s.startsWith('{') && s.endsWith('}')) ||
|
(s.startsWith('{') && s.endsWith('}')) ||
|
||||||
(s.startsWith('[') && s.endsWith(']'))
|
(s.startsWith('[') && s.endsWith(']'))
|
||||||
@ -681,7 +711,8 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
|
|||||||
// Keep actual media URLs as video.
|
// Keep actual media URLs as video.
|
||||||
!/\.(mp4|m3u8|flv|webm|mov|m4v|ogv)(\?|#|$)/i.test(urlLike) &&
|
!/\.(mp4|m3u8|flv|webm|mov|m4v|ogv)(\?|#|$)/i.test(urlLike) &&
|
||||||
!/^data:video\//i.test(urlLike) &&
|
!/^data:video\//i.test(urlLike) &&
|
||||||
!/^(rtsp|rtmp):\/\//i.test(urlLike);
|
!/^(rtsp|rtmp|webrtc|srt):\/\//i.test(urlLike) &&
|
||||||
|
!/^wss?:\/\//i.test(urlLike);
|
||||||
|
|
||||||
// Prefer evidence from the option payload over the widget key.
|
// Prefer evidence from the option payload over the widget key.
|
||||||
// Many forks mislabel widget keys (e.g. "Text*" / "Image*"), but the option payload
|
// Many forks mislabel widget keys (e.g. "Text*" / "Image*"), but the option payload
|
||||||
|
|||||||
@ -18,6 +18,11 @@ export interface GoViewIframeOption {
|
|||||||
frameSrc?: unknown;
|
frameSrc?: unknown;
|
||||||
webUrl?: unknown;
|
webUrl?: unknown;
|
||||||
webpageUrl?: unknown;
|
webpageUrl?: unknown;
|
||||||
|
pageUrl?: unknown;
|
||||||
|
h5Url?: unknown;
|
||||||
|
// generic link-ish fields seen in some exports
|
||||||
|
link?: unknown;
|
||||||
|
href?: unknown;
|
||||||
|
|
||||||
// HTML/embed variants
|
// HTML/embed variants
|
||||||
html?: unknown;
|
html?: unknown;
|
||||||
@ -32,6 +37,8 @@ export interface GoViewIframeOption {
|
|||||||
sources?: unknown;
|
sources?: unknown;
|
||||||
sourceList?: unknown;
|
sourceList?: unknown;
|
||||||
urlList?: unknown;
|
urlList?: unknown;
|
||||||
|
srcList?: unknown;
|
||||||
|
iframeList?: unknown;
|
||||||
|
|
||||||
allow?: unknown;
|
allow?: unknown;
|
||||||
sandbox?: unknown;
|
sandbox?: unknown;
|
||||||
@ -200,6 +207,10 @@ function pickSrc(option: GoViewIframeOption): string {
|
|||||||
frameSrc: option.frameSrc,
|
frameSrc: option.frameSrc,
|
||||||
webUrl: option.webUrl,
|
webUrl: option.webUrl,
|
||||||
webpageUrl: option.webpageUrl,
|
webpageUrl: option.webpageUrl,
|
||||||
|
pageUrl: option.pageUrl,
|
||||||
|
h5Url: option.h5Url,
|
||||||
|
link: option.link,
|
||||||
|
href: option.href,
|
||||||
}) ||
|
}) ||
|
||||||
pickUrlLike(option) ||
|
pickUrlLike(option) ||
|
||||||
pickUrlLike(option.dataset) ||
|
pickUrlLike(option.dataset) ||
|
||||||
@ -225,7 +236,7 @@ function pickSrc(option: GoViewIframeOption): string {
|
|||||||
const listUrl = pickFromNested(
|
const listUrl = pickFromNested(
|
||||||
option,
|
option,
|
||||||
(obj) => {
|
(obj) => {
|
||||||
for (const key of ['sources', 'sourceList', 'urlList']) {
|
for (const key of ['sources', 'sourceList', 'urlList', 'srcList', 'iframeList']) {
|
||||||
const v = pickFirstUrlFromList(obj[key]);
|
const v = pickFirstUrlFromList(obj[key]);
|
||||||
if (v) return v;
|
if (v) return v;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,13 @@ export interface GoViewVideoOption {
|
|||||||
srcUrl?: unknown;
|
srcUrl?: unknown;
|
||||||
sourceUrl?: unknown;
|
sourceUrl?: unknown;
|
||||||
|
|
||||||
|
// streaming-ish aliases
|
||||||
|
webrtcUrl?: unknown;
|
||||||
|
rtcUrl?: unknown;
|
||||||
|
wsUrl?: unknown;
|
||||||
|
srtUrl?: unknown;
|
||||||
|
dashUrl?: unknown;
|
||||||
|
|
||||||
// common alternative shapes
|
// common alternative shapes
|
||||||
sources?: unknown;
|
sources?: unknown;
|
||||||
sourceList?: unknown;
|
sourceList?: unknown;
|
||||||
@ -204,6 +211,11 @@ function pickFirstUrlFromList(input: unknown): string {
|
|||||||
'hlsUrl',
|
'hlsUrl',
|
||||||
'flvUrl',
|
'flvUrl',
|
||||||
'm3u8Url',
|
'm3u8Url',
|
||||||
|
'webrtcUrl',
|
||||||
|
'rtcUrl',
|
||||||
|
'wsUrl',
|
||||||
|
'srtUrl',
|
||||||
|
'dashUrl',
|
||||||
'cameraUrl',
|
'cameraUrl',
|
||||||
'cctvUrl',
|
'cctvUrl',
|
||||||
'monitorUrl',
|
'monitorUrl',
|
||||||
@ -242,6 +254,11 @@ function pickSrc(option: GoViewVideoOption): string {
|
|||||||
'hlsUrl',
|
'hlsUrl',
|
||||||
'flvUrl',
|
'flvUrl',
|
||||||
'm3u8Url',
|
'm3u8Url',
|
||||||
|
'webrtcUrl',
|
||||||
|
'rtcUrl',
|
||||||
|
'wsUrl',
|
||||||
|
'srtUrl',
|
||||||
|
'dashUrl',
|
||||||
'cameraUrl',
|
'cameraUrl',
|
||||||
'cctvUrl',
|
'cctvUrl',
|
||||||
'monitorUrl',
|
'monitorUrl',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user