feat: add TikTok embed support

This commit is contained in:
2026-03-24 00:14:53 +11:00
parent 4f1179d5cd
commit a8eb404ff3
10 changed files with 589 additions and 36 deletions
@@ -12,6 +12,7 @@ import * as css from './UrlPreviewCard.css';
import { tryDecodeURIComponent } from '../../utils/dom';
import { mxcUrlToHttp } from '../../utils/matrix';
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
import { useAuthenticatedMediaUrl } from '../../hooks/useAuthenticatedMediaUrl';
import { openExternalUrl } from '../../utils/tauri';
const linkStyles = { color: color.Success.Main };
@@ -27,6 +28,18 @@ const handleExternalLinkClick = (e: MouseEvent<HTMLAnchorElement>) => {
}
};
/**
* Preview image component with authentication support
*/
const AuthenticatedUrlPreviewImg = ({
src,
useAuthentication,
...props
}: React.ComponentProps<typeof UrlPreviewImg> & { useAuthentication: boolean }) => {
const authenticatedSrc = useAuthenticatedMediaUrl(src, useAuthentication);
return <UrlPreviewImg src={authenticatedSrc} {...props} />;
};
export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
({ url, ts, ...props }, ref) => {
const mx = useMatrixClient();
@@ -36,10 +49,22 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
);
useEffect(() => {
loadPreview().catch(() => {
// Error is already handled by AsyncStatus.Error state
loadPreview().catch((error) => {
// Log preview errors for debugging - common causes:
// - 502/503: Matrix server's URL preview service is down/misconfigured
// - 404: URL preview endpoint not available on this server
// - Network errors: connectivity issues
if (error?.httpStatus === 502 || error?.httpStatus === 503) {
// Server's URL preview backend is down - this is a server-side issue
// eslint-disable-next-line no-console
console.warn('[UrlPreview] Server URL preview service unavailable (502/503):', url);
} else if (error?.httpStatus === 404) {
// Server doesn't support URL previews
// eslint-disable-next-line no-console
console.info('[UrlPreview] Server does not support URL previews:', url);
}
});
}, [loadPreview]);
}, [loadPreview, url]);
if (previewStatus.status === AsyncStatus.Error) return null;
@@ -57,8 +82,9 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number }>(
return (
<>
{imgUrl && (
<UrlPreviewImg
<AuthenticatedUrlPreviewImg
src={imgUrl}
useAuthentication={useAuthentication}
alt={prev['og:title']}
title={prev['og:title']}
style={isSvg ? { padding: '10px' } : undefined}