Remove the TikTok embeds and the raw oEmbed HTML injection. [skip build]
This commit is contained in:
@@ -30,8 +30,6 @@ import {
|
||||
UrlPreviewHolder,
|
||||
YouTubeEmbed,
|
||||
isYouTubeUrl,
|
||||
TikTokEmbed,
|
||||
isTikTokUrl,
|
||||
GiphyEmbed,
|
||||
isGiphyUrl,
|
||||
} from './url-preview';
|
||||
@@ -88,11 +86,8 @@ export function RenderMessageContent({
|
||||
|
||||
// Separate special URLs from generic ones
|
||||
const youtubeUrls = filteredUrls.filter(isYouTubeUrl);
|
||||
const tiktokUrls = filteredUrls.filter(isTikTokUrl);
|
||||
const giphyUrls = filteredUrls.filter(isGiphyUrl);
|
||||
const otherUrls = filteredUrls.filter(
|
||||
(url) => !isYouTubeUrl(url) && !isTikTokUrl(url) && !isGiphyUrl(url),
|
||||
);
|
||||
const otherUrls = filteredUrls.filter((url) => !isYouTubeUrl(url) && !isGiphyUrl(url));
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -100,10 +95,6 @@ export function RenderMessageContent({
|
||||
{youtubeUrls.map((url) => (
|
||||
<YouTubeEmbed key={url} url={url} />
|
||||
))}
|
||||
{/* Render TikTok embeds */}
|
||||
{tiktokUrls.map((url) => (
|
||||
<TikTokEmbed key={url} url={url} />
|
||||
))}
|
||||
{/* Render Giphy embeds */}
|
||||
{giphyUrls.map((url) => (
|
||||
<GiphyEmbed key={url} url={url} />
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
import { style } from '@vanilla-extract/css';
|
||||
import { DefaultReset, color, config, toRem } from 'folds';
|
||||
|
||||
export const TikTokEmbed = style([
|
||||
DefaultReset,
|
||||
{
|
||||
width: toRem(360),
|
||||
maxWidth: '100%',
|
||||
backgroundColor: color.SurfaceVariant.Container,
|
||||
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
|
||||
borderRadius: config.radii.R300,
|
||||
overflow: 'hidden',
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokEmbedHeader = style([
|
||||
DefaultReset,
|
||||
{
|
||||
padding: `${config.space.S200} ${config.space.S300}`,
|
||||
backgroundColor: color.SurfaceVariant.ContainerActive,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: config.space.S200,
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokEmbedInfo = style([
|
||||
DefaultReset,
|
||||
{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: config.space.S100,
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokEmbedTitle = style({
|
||||
color: color.Primary.Main,
|
||||
textDecoration: 'none',
|
||||
fontWeight: config.fontWeight.W500,
|
||||
':hover': {
|
||||
textDecoration: 'underline',
|
||||
},
|
||||
});
|
||||
|
||||
export const TikTokEmbedAuthor = style({
|
||||
color: color.SurfaceVariant.OnContainer,
|
||||
textDecoration: 'none',
|
||||
opacity: 0.8,
|
||||
':hover': {
|
||||
textDecoration: 'underline',
|
||||
opacity: 1,
|
||||
},
|
||||
});
|
||||
|
||||
export const TikTokEmbedLink = style({
|
||||
color: color.Success.Main,
|
||||
textDecoration: 'none',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
':hover': {
|
||||
textDecoration: 'underline',
|
||||
},
|
||||
});
|
||||
|
||||
export const TikTokThumbnailContainer = style([
|
||||
DefaultReset,
|
||||
{
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
height: toRem(550),
|
||||
backgroundColor: '#000',
|
||||
display: 'block',
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokThumbnailButton = style([
|
||||
DefaultReset,
|
||||
{
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
height: toRem(550),
|
||||
border: 'none',
|
||||
padding: 0,
|
||||
cursor: 'pointer',
|
||||
backgroundColor: '#000',
|
||||
display: 'block',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokThumbnail = style([
|
||||
DefaultReset,
|
||||
{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
display: 'block',
|
||||
objectFit: 'cover',
|
||||
objectPosition: 'center',
|
||||
},
|
||||
]);
|
||||
|
||||
export const TikTokEmbedContainer = style([
|
||||
DefaultReset,
|
||||
{
|
||||
width: '100%',
|
||||
height: toRem(550),
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: '#000',
|
||||
border: 'none',
|
||||
display: 'block',
|
||||
},
|
||||
]);
|
||||
@@ -1,277 +0,0 @@
|
||||
import React, { MouseEvent, useEffect, useState } from 'react';
|
||||
import { Box, Spinner, Text, as } from 'folds';
|
||||
import * as css from './TikTokEmbed.css';
|
||||
import { openExternalUrl } from '../../utils/tauri';
|
||||
|
||||
/**
|
||||
* Regex patterns to match TikTok URLs
|
||||
*/
|
||||
const TIKTOK_URL_PATTERNS = [
|
||||
// Standard tiktok.com/@username/video/VIDEO_ID
|
||||
/(?:https?:\/\/)?(?:www\.)?tiktok\.com\/@[\w.-]+\/video\/(\d+)/i,
|
||||
// Short vm.tiktok.com/VIDEO_CODE
|
||||
/(?:https?:\/\/)?(?:www\.)?vm\.tiktok\.com\/([\w]+)/i,
|
||||
// Short vt.tiktok.com/VIDEO_CODE
|
||||
/(?:https?:\/\/)?(?:www\.)?vt\.tiktok\.com\/([\w]+)/i,
|
||||
// Mobile m.tiktok.com
|
||||
/(?:https?:\/\/)?(?:www\.)?m\.tiktok\.com\/v\/(\d+)/i,
|
||||
];
|
||||
|
||||
/**
|
||||
* TikTok oEmbed API base
|
||||
*/
|
||||
const TIKTOK_OEMBED_API = 'https://www.tiktok.com/oembed';
|
||||
|
||||
/**
|
||||
* Click handler for external links - uses Tauri shell on desktop/mobile
|
||||
*/
|
||||
const handleExternalLinkClick = (e: MouseEvent<HTMLAnchorElement>) => {
|
||||
const { href } = e.currentTarget;
|
||||
if (href && (href.startsWith('http://') || href.startsWith('https://'))) {
|
||||
e.preventDefault();
|
||||
openExternalUrl(href);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a URL is a TikTok URL
|
||||
* @param url The URL to check
|
||||
* @returns True if the URL is a TikTok URL
|
||||
*/
|
||||
export function isTikTokUrl(url: string): boolean {
|
||||
return TIKTOK_URL_PATTERNS.some((pattern) => pattern.test(url));
|
||||
}
|
||||
|
||||
function extractTikTokVideoId(url: string, embedHtml = ''): string | null {
|
||||
const urlMatch = url.match(/\/video\/(\d+)/i) ?? url.match(/\/v\/(\d+)/i);
|
||||
const embedMatch = embedHtml.match(/data-video-id=["'](\d+)["']/i);
|
||||
return urlMatch?.[1] ?? embedMatch?.[1] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches TikTok video metadata using oEmbed API
|
||||
* @param url The TikTok video URL
|
||||
* @returns Video metadata including title, author, and thumbnail
|
||||
*/
|
||||
async function fetchTikTokOEmbed(url: string): Promise<{
|
||||
title: string;
|
||||
authorName: string;
|
||||
authorUrl: string;
|
||||
thumbnailUrl: string;
|
||||
embedHtml: string;
|
||||
videoId: string | null;
|
||||
} | null> {
|
||||
try {
|
||||
const { electron } = window as any;
|
||||
let data;
|
||||
if (electron?.tiktok?.getOEmbed) {
|
||||
data = await electron.tiktok.getOEmbed(url);
|
||||
} 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 {
|
||||
title: data.title || 'TikTok Video',
|
||||
authorName: data.author_name || 'Unknown',
|
||||
authorUrl: data.author_url || url,
|
||||
thumbnailUrl: data.thumbnail_url || '',
|
||||
embedHtml: data.html || '',
|
||||
videoId: extractTikTokVideoId(url, data.html || ''),
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
type TikTokEmbedState =
|
||||
| { status: 'loading' }
|
||||
| {
|
||||
status: 'loaded';
|
||||
title: string;
|
||||
authorName: string;
|
||||
authorUrl: string;
|
||||
thumbnailUrl: string;
|
||||
embedHtml: string;
|
||||
videoId: string | null;
|
||||
}
|
||||
| { status: 'error' };
|
||||
|
||||
type TikTokEmbedProps = {
|
||||
/** The original TikTok URL */
|
||||
url: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* TikTok embed component that shows video preview with metadata
|
||||
*/
|
||||
export const TikTokEmbed = as<'div', TikTokEmbedProps>(({ url, ...props }, ref) => {
|
||||
const [state, setState] = useState<TikTokEmbedState>({ status: 'loading' });
|
||||
const [showPlayer, setShowPlayer] = useState(false);
|
||||
|
||||
// Fetch video info on mount
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
fetchTikTokOEmbed(url).then((info) => {
|
||||
if (cancelled) return;
|
||||
|
||||
if (info) {
|
||||
setState({
|
||||
status: 'loaded',
|
||||
title: info.title,
|
||||
authorName: info.authorName,
|
||||
authorUrl: info.authorUrl,
|
||||
thumbnailUrl: info.thumbnailUrl,
|
||||
embedHtml: info.embedHtml,
|
||||
videoId: info.videoId,
|
||||
});
|
||||
} else {
|
||||
setState({ status: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [url]);
|
||||
|
||||
// Loading state
|
||||
if (state.status === 'loading') {
|
||||
return (
|
||||
<Box shrink="No" className={css.TikTokEmbed} direction="Column" {...props} ref={ref}>
|
||||
<div className={css.TikTokEmbedHeader}>
|
||||
<Text
|
||||
as="a"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
size="T200"
|
||||
className={css.TikTokEmbedLink}
|
||||
onClick={handleExternalLinkClick}
|
||||
truncate
|
||||
>
|
||||
TikTok - Loading...
|
||||
</Text>
|
||||
</div>
|
||||
<Box
|
||||
className={css.TikTokThumbnailContainer}
|
||||
alignItems="Center"
|
||||
justifyContent="Center"
|
||||
style={{ background: '#000', display: 'flex' }}
|
||||
>
|
||||
<Spinner variant="Secondary" size="600" />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
// Error state - show basic link
|
||||
if (state.status === 'error') {
|
||||
return (
|
||||
<Box shrink="No" className={css.TikTokEmbed} direction="Column" {...props} ref={ref}>
|
||||
<div className={css.TikTokEmbedHeader}>
|
||||
<Text
|
||||
as="a"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
size="T200"
|
||||
className={css.TikTokEmbedLink}
|
||||
onClick={handleExternalLinkClick}
|
||||
truncate
|
||||
>
|
||||
TikTok Video
|
||||
</Text>
|
||||
</div>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
// Loaded state - show thumbnail or embed
|
||||
if (!showPlayer) {
|
||||
return (
|
||||
<Box shrink="No" className={css.TikTokEmbed} direction="Column" {...props} ref={ref}>
|
||||
<div className={css.TikTokEmbedHeader}>
|
||||
<div className={css.TikTokEmbedInfo}>
|
||||
<Text
|
||||
as="a"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
size="T300"
|
||||
className={css.TikTokEmbedTitle}
|
||||
onClick={handleExternalLinkClick}
|
||||
truncate
|
||||
>
|
||||
{state.title}
|
||||
</Text>
|
||||
<Text
|
||||
as="a"
|
||||
href={state.authorUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
size="T200"
|
||||
className={css.TikTokEmbedAuthor}
|
||||
onClick={handleExternalLinkClick}
|
||||
truncate
|
||||
>
|
||||
{state.authorName}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className={css.TikTokThumbnailButton}
|
||||
onClick={() => setShowPlayer(true)}
|
||||
aria-label="Play TikTok video"
|
||||
>
|
||||
{state.thumbnailUrl ? (
|
||||
<img src={state.thumbnailUrl} alt={state.title} className={css.TikTokThumbnail} />
|
||||
) : null}
|
||||
</button>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
const playerUrl = state.videoId
|
||||
? `https://www.tiktok.com/player/v1/${state.videoId}?autoplay=1`
|
||||
: null;
|
||||
|
||||
// Use TikTok's documented player instead of injecting the oEmbed script.
|
||||
return (
|
||||
<Box shrink="No" className={css.TikTokEmbed} direction="Column" {...props} ref={ref}>
|
||||
<div className={css.TikTokEmbedHeader}>
|
||||
<Text
|
||||
as="a"
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
size="T200"
|
||||
className={css.TikTokEmbedLink}
|
||||
onClick={handleExternalLinkClick}
|
||||
truncate
|
||||
>
|
||||
{state.title}
|
||||
</Text>
|
||||
</div>
|
||||
{playerUrl ? (
|
||||
<iframe
|
||||
className={css.TikTokEmbedContainer}
|
||||
src={playerUrl}
|
||||
title="TikTok video player"
|
||||
allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
|
||||
allowFullScreen
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
className={css.TikTokEmbedContainer}
|
||||
dangerouslySetInnerHTML={{ __html: state.embedHtml }}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './UrlPreview';
|
||||
export * from './UrlPreviewCard';
|
||||
export * from './YouTubeEmbed';
|
||||
export * from './TikTokEmbed';
|
||||
export * from './GiphyEmbed';
|
||||
|
||||
Reference in New Issue
Block a user