Skip to content

Commit

Permalink
Experimental untested solution to unknown files
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Feb 4, 2025
1 parent a3fc396 commit 4ed92e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/components/media.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLingui } from '@lingui/react/macro';
import { Trans, useLingui } from '@lingui/react/macro';
import { getBlurHashAverageColor } from 'fast-blurhash';
import { Fragment } from 'preact';
import { memo } from 'preact/compat';
Expand Down Expand Up @@ -165,9 +165,12 @@ function Media({
onUpdate,
};

const [mediaLoadError, setMediaLoadError] = useState(false);

const Parent = useMemo(
() => (to ? (props) => <Link to={to} {...props} /> : 'div'),
[to],
() =>
to && !mediaLoadError ? (props) => <Link to={to} {...props} /> : 'div',
[to, mediaLoadError],
);

const remoteMediaURLObj = remoteMediaURL ? getURLObj(remoteMediaURL) : null;
Expand Down Expand Up @@ -392,6 +395,8 @@ function Media({
const { src } = e.target;
if (src === mediaURL && mediaURL !== remoteMediaURL) {
e.target.src = remoteMediaURL;
} else {
setMediaLoadError(true);
}
}}
/>
Expand All @@ -401,6 +406,16 @@ function Media({
</>
)}
</Parent>
{mediaLoadError && (
<div>
<a href={remoteUrl} class="button plain6 small" target="_blank">
<Icon icon="external" />{' '}
<span>
<Trans>Open file</Trans>
</span>
</a>
</div>
)}
</Figure>
);
} else if (type === 'gifv' || type === 'video' || isVideoMaybe) {
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ed92e7

Please sign in to comment.