Fetch the TikTok oEmbed through the main process in Electron and drop the thumbnail crossOrigin.
Trigger cinny-mobile / dispatch (push) Successful in 1s
Trigger cinny-mobile / dispatch (push) Successful in 1s
This commit is contained in:
@@ -62,11 +62,17 @@ async function fetchTikTokOEmbed(url: string): Promise<{
|
|||||||
videoId: string | null;
|
videoId: string | null;
|
||||||
} | null> {
|
} | null> {
|
||||||
try {
|
try {
|
||||||
const oembedUrl = `${TIKTOK_OEMBED_API}?url=${encodeURIComponent(url)}`;
|
const electron = (window as any).electron;
|
||||||
const response = await fetch(oembedUrl);
|
let data;
|
||||||
if (!response.ok) return null;
|
if (electron?.tiktok?.getOEmbed) {
|
||||||
|
data = await electron.tiktok.getOEmbed(url);
|
||||||
const data = await response.json();
|
} else {
|
||||||
|
const oembedUrl = `${TIKTOK_OEMBED_API}?url=${encodeURIComponent(url)}`;
|
||||||
|
const response = await fetch(oembedUrl);
|
||||||
|
if (!response.ok) return null;
|
||||||
|
data = await response.json();
|
||||||
|
}
|
||||||
|
if (!data) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: data.title || 'TikTok Video',
|
title: data.title || 'TikTok Video',
|
||||||
@@ -224,12 +230,7 @@ export const TikTokEmbed = as<'div', TikTokEmbedProps>(({ url, ...props }, ref)
|
|||||||
aria-label="Play TikTok video"
|
aria-label="Play TikTok video"
|
||||||
>
|
>
|
||||||
{state.thumbnailUrl ? (
|
{state.thumbnailUrl ? (
|
||||||
<img
|
<img src={state.thumbnailUrl} alt={state.title} className={css.TikTokThumbnail} />
|
||||||
src={state.thumbnailUrl}
|
|
||||||
alt={state.title}
|
|
||||||
className={css.TikTokThumbnail}
|
|
||||||
crossOrigin="anonymous"
|
|
||||||
/>
|
|
||||||
) : null}
|
) : null}
|
||||||
</button>
|
</button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user