mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 08:48:47 +01:00
Experimental untested solution to unknown files
This commit is contained in:
parent
a3fc396738
commit
4ed92e7c84
2 changed files with 22 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { useLingui } from '@lingui/react/macro';
|
import { Trans, useLingui } from '@lingui/react/macro';
|
||||||
import { getBlurHashAverageColor } from 'fast-blurhash';
|
import { getBlurHashAverageColor } from 'fast-blurhash';
|
||||||
import { Fragment } from 'preact';
|
import { Fragment } from 'preact';
|
||||||
import { memo } from 'preact/compat';
|
import { memo } from 'preact/compat';
|
||||||
|
@ -165,9 +165,12 @@ function Media({
|
||||||
onUpdate,
|
onUpdate,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [mediaLoadError, setMediaLoadError] = useState(false);
|
||||||
|
|
||||||
const Parent = useMemo(
|
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;
|
const remoteMediaURLObj = remoteMediaURL ? getURLObj(remoteMediaURL) : null;
|
||||||
|
@ -392,6 +395,8 @@ function Media({
|
||||||
const { src } = e.target;
|
const { src } = e.target;
|
||||||
if (src === mediaURL && mediaURL !== remoteMediaURL) {
|
if (src === mediaURL && mediaURL !== remoteMediaURL) {
|
||||||
e.target.src = remoteMediaURL;
|
e.target.src = remoteMediaURL;
|
||||||
|
} else {
|
||||||
|
setMediaLoadError(true);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -401,6 +406,16 @@ function Media({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Parent>
|
</Parent>
|
||||||
|
{mediaLoadError && (
|
||||||
|
<div>
|
||||||
|
<a href={remoteUrl} class="button plain6 small" target="_blank">
|
||||||
|
<Icon icon="external" />{' '}
|
||||||
|
<span>
|
||||||
|
<Trans>Open file</Trans>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Figure>
|
</Figure>
|
||||||
);
|
);
|
||||||
} else if (type === 'gifv' || type === 'video' || isVideoMaybe) {
|
} else if (type === 'gifv' || type === 'video' || isVideoMaybe) {
|
||||||
|
|
4
src/locales/en.po
generated
4
src/locales/en.po
generated
|
@ -1284,6 +1284,10 @@ msgstr ""
|
||||||
msgid "Filtered"
|
msgid "Filtered"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/components/media.jsx:414
|
||||||
|
msgid "Open file"
|
||||||
|
msgstr "Open file"
|
||||||
|
|
||||||
#: src/components/modals.jsx:73
|
#: src/components/modals.jsx:73
|
||||||
msgid "Post published. Check it out."
|
msgid "Post published. Check it out."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
Loading…
Reference in a new issue