Handle unknown audio attachments

This commit is contained in:
Lim Chee Aun 2024-01-24 13:08:54 +08:00
parent 725da37063
commit 990f2b2e29

View file

@ -151,11 +151,19 @@ function Media({
[to],
);
const remoteMediaURLObj = remoteMediaURL ? new URL(remoteMediaURL) : null;
const isVideoMaybe =
type === 'unknown' &&
/\.(mp4|m4a|m4p|m4b|m4r|m4v|mov|webm)$/i.test(remoteMediaURL);
remoteMediaURLObj &&
/\.(mp4|m4r|m4v|mov|webm)$/i.test(remoteMediaURLObj.pathname);
const isAudioMaybe =
type === 'unknown' &&
remoteMediaURLObj &&
/\.(mp3|ogg|wav|m4a|m4p|m4b)$/i.test(remoteMediaURLObj.pathname);
console.log('render media', remoteMediaURL, remoteMediaURLObj, isAudioMaybe);
const isImage =
type === 'image' || (type === 'unknown' && previewUrl && !isVideoMaybe);
type === 'image' ||
(type === 'unknown' && previewUrl && !isVideoMaybe && !isAudioMaybe);
const parentRef = useRef();
const [imageSmallerThanParent, setImageSmallerThanParent] = useState(false);
@ -476,7 +484,7 @@ function Media({
</Parent>
</Figure>
);
} else if (type === 'audio') {
} else if (type === 'audio' || isAudioMaybe) {
const formattedDuration = formatDuration(original.duration);
return (
<Figure>
@ -499,6 +507,12 @@ function Media({
height={height}
data-orientation={orientation}
loading="lazy"
onError={(e) => {
try {
// Remove self if broken
e.target?.remove?.();
} catch (e) {}
}}
/>
) : null}
{!showOriginal && (