mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 17:16:26 +01:00
Handle unknown audio attachments
This commit is contained in:
parent
725da37063
commit
990f2b2e29
1 changed files with 17 additions and 3 deletions
|
@ -151,11 +151,19 @@ function Media({
|
||||||
[to],
|
[to],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const remoteMediaURLObj = remoteMediaURL ? new URL(remoteMediaURL) : null;
|
||||||
const isVideoMaybe =
|
const isVideoMaybe =
|
||||||
type === 'unknown' &&
|
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 =
|
const isImage =
|
||||||
type === 'image' || (type === 'unknown' && previewUrl && !isVideoMaybe);
|
type === 'image' ||
|
||||||
|
(type === 'unknown' && previewUrl && !isVideoMaybe && !isAudioMaybe);
|
||||||
|
|
||||||
const parentRef = useRef();
|
const parentRef = useRef();
|
||||||
const [imageSmallerThanParent, setImageSmallerThanParent] = useState(false);
|
const [imageSmallerThanParent, setImageSmallerThanParent] = useState(false);
|
||||||
|
@ -476,7 +484,7 @@ function Media({
|
||||||
</Parent>
|
</Parent>
|
||||||
</Figure>
|
</Figure>
|
||||||
);
|
);
|
||||||
} else if (type === 'audio') {
|
} else if (type === 'audio' || isAudioMaybe) {
|
||||||
const formattedDuration = formatDuration(original.duration);
|
const formattedDuration = formatDuration(original.duration);
|
||||||
return (
|
return (
|
||||||
<Figure>
|
<Figure>
|
||||||
|
@ -499,6 +507,12 @@ function Media({
|
||||||
height={height}
|
height={height}
|
||||||
data-orientation={orientation}
|
data-orientation={orientation}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
|
onError={(e) => {
|
||||||
|
try {
|
||||||
|
// Remove self if broken
|
||||||
|
e.target?.remove?.();
|
||||||
|
} catch (e) {}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
{!showOriginal && (
|
{!showOriginal && (
|
||||||
|
|
Loading…
Reference in a new issue