refactor(goview): deepen iframe/video import heuristics
This commit is contained in:
parent
9ac5bbaa09
commit
00cfb9111d
@ -345,7 +345,7 @@ function looksLikeIframeOption(option: unknown): boolean {
|
||||
if (containsVideoHtmlDeep(option, 2)) return false;
|
||||
|
||||
if (
|
||||
hasAnyKeyDeep(option, ['iframeUrl', 'iframeSrc', 'embedUrl', 'frameUrl', 'frameSrc'], 2) ||
|
||||
hasAnyKeyDeep(option, ['iframeUrl', 'iframeSrc', 'embedUrl', 'frameUrl', 'frameSrc'], 3) ||
|
||||
// Some exports store raw HTML instead of a URL.
|
||||
hasAnyKeyDeep(
|
||||
option,
|
||||
@ -365,7 +365,7 @@ function looksLikeIframeOption(option: unknown): boolean {
|
||||
'content',
|
||||
'template',
|
||||
],
|
||||
2,
|
||||
3,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
@ -459,7 +459,7 @@ function looksLikeVideoOption(option: unknown): boolean {
|
||||
'poster',
|
||||
'posterUrl',
|
||||
],
|
||||
2,
|
||||
3,
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
@ -678,7 +678,7 @@ export function convertGoViewProjectToScreen(input: GoViewProjectLike | GoViewSt
|
||||
const urlLike = pickUrlLike(option);
|
||||
const urlLooksLikeEmbedPage =
|
||||
!!urlLike &&
|
||||
/(youtube\.com|youtu\.be|vimeo\.com|bilibili\.com|youku\.com|iqiyi\.com|tencent|qq\.com|mgtv\.com|ixigua\.com|huya\.com|douyu\.com|twitch\.tv|douyin\.com|kuaishou\.com)/i.test(
|
||||
/(youtube\.com|youtu\.be|vimeo\.com|twitch\.tv|tiktok\.com|douyin\.com|kuaishou\.com|ixigua\.com|huya\.com|douyu\.com|bilibili\.com|live\.bilibili\.com|player\.bilibili\.com|youku\.com|iqiyi\.com|mgtv\.com|tencent|qq\.com|music\.163\.com)/i.test(
|
||||
urlLike,
|
||||
) &&
|
||||
// Keep actual media URLs as video.
|
||||
|
||||
@ -178,7 +178,7 @@ function pickSrc(option: GoViewIframeOption): string {
|
||||
obj.template;
|
||||
return typeof v === 'string' ? v : undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
if (html) return toDataHtmlUrl(html);
|
||||
|
||||
@ -192,7 +192,7 @@ function pickSrc(option: GoViewIframeOption): string {
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
|
||||
if (!listUrl) return '';
|
||||
@ -216,7 +216,7 @@ function pickFit(option: GoViewIframeOption): IframeWidgetNode['props']['fit'] |
|
||||
function pickAspectRatio(option: GoViewIframeOption): number | undefined {
|
||||
const direct = toMaybeNumber(option.aspectRatio ?? option.ratio);
|
||||
if (direct !== undefined && direct > 0) return direct;
|
||||
const nested = pickFromNested(option, (obj) => toMaybeNumber(obj.aspectRatio ?? obj.aspect ?? obj.ratio), 2);
|
||||
const nested = pickFromNested(option, (obj) => toMaybeNumber(obj.aspectRatio ?? obj.aspect ?? obj.ratio), 3);
|
||||
if (nested !== undefined && nested > 0) return nested;
|
||||
return undefined;
|
||||
}
|
||||
@ -237,14 +237,14 @@ function pickStringLike(option: GoViewIframeOption, keys: string[]): string | un
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
}
|
||||
|
||||
function pickBorderRadius(option: GoViewIframeOption): number | undefined {
|
||||
const direct = toMaybeNumber(option.borderRadius);
|
||||
if (direct !== undefined) return direct;
|
||||
return pickFromNested(option, (obj) => toMaybeNumber(obj.borderRadius ?? obj.radius ?? obj.r), 2);
|
||||
return pickFromNested(option, (obj) => toMaybeNumber(obj.borderRadius ?? obj.radius ?? obj.r), 3);
|
||||
}
|
||||
|
||||
export function convertGoViewIframeOptionToNodeProps(option: GoViewIframeOption): IframeWidgetNode['props'] {
|
||||
|
||||
@ -226,7 +226,7 @@ function pickSrc(option: GoViewVideoOption): string {
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
if (fromDirect) return normalizeSrcMaybeFromHtml(fromDirect);
|
||||
|
||||
@ -240,7 +240,7 @@ function pickSrc(option: GoViewVideoOption): string {
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
if (fromList) return normalizeSrcMaybeFromHtml(fromList);
|
||||
|
||||
@ -258,7 +258,7 @@ function pickBorderRadius(option: GoViewVideoOption): number | undefined {
|
||||
const direct = toMaybeNumber(option.borderRadius);
|
||||
if (direct !== undefined) return direct;
|
||||
|
||||
return pickFromNested(option, (obj) => toMaybeNumber(obj.borderRadius ?? obj.radius ?? obj.r), 2);
|
||||
return pickFromNested(option, (obj) => toMaybeNumber(obj.borderRadius ?? obj.radius ?? obj.r), 3);
|
||||
}
|
||||
|
||||
function pickBooleanLike(option: GoViewVideoOption, keys: string[]): boolean | undefined {
|
||||
@ -271,7 +271,7 @@ function pickBooleanLike(option: GoViewVideoOption, keys: string[]): boolean | u
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ function pickFitFromNested(option: GoViewVideoOption): string {
|
||||
const direct = asString(option.fit) || asString(option.objectFit);
|
||||
if (direct) return direct;
|
||||
|
||||
const nested = pickFromNested(option, (obj) => asString(obj.fit) || asString(obj.objectFit), 2);
|
||||
const nested = pickFromNested(option, (obj) => asString(obj.fit) || asString(obj.objectFit), 3);
|
||||
return nested ?? '';
|
||||
}
|
||||
|
||||
@ -350,14 +350,14 @@ function pickPoster(option: GoViewVideoOption): string | undefined {
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
2,
|
||||
3,
|
||||
);
|
||||
}
|
||||
|
||||
function pickAspectRatio(option: GoViewVideoOption): number | undefined {
|
||||
const direct = toMaybeNumber(option.aspectRatio ?? option.ratio);
|
||||
if (direct !== undefined && direct > 0) return direct;
|
||||
const nested = pickFromNested(option, (obj) => toMaybeNumber(obj.aspectRatio ?? obj.aspect ?? obj.ratio), 2);
|
||||
const nested = pickFromNested(option, (obj) => toMaybeNumber(obj.aspectRatio ?? obj.aspect ?? obj.ratio), 3);
|
||||
if (nested !== undefined && nested > 0) return nested;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user