mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 05:54:19 +01:00
update
This commit is contained in:
@@ -1,29 +1,13 @@
|
||||
import { Component, createSignal, Show } from 'solid-js';
|
||||
import { ContentWarning } from '@/core/event';
|
||||
import { Component, createEffect, createSignal, Show } from 'solid-js';
|
||||
import { fixUrl } from '@/utils/imageUrl';
|
||||
|
||||
type ImageDisplayProps = {
|
||||
url: string;
|
||||
contentWarning: ContentWarning;
|
||||
};
|
||||
|
||||
const fixUrl = (url: URL): string => {
|
||||
const result = new URL(url);
|
||||
if (url.host === 'i.imgur.com') {
|
||||
const match = url.pathname.match(/^\/([a-zA-Z0-9]+)\.(jpg|jpeg|png|gif)/);
|
||||
if (match != null) {
|
||||
const imageId = match[1];
|
||||
result.pathname = `${imageId}l.webp`;
|
||||
}
|
||||
} else if (url.host === 'i.gyazo.com') {
|
||||
result.host = 'thumb.gyazo.com';
|
||||
result.pathname = `/thumb/640_w${url.pathname}`;
|
||||
}
|
||||
return result.toString();
|
||||
initialHidden: boolean;
|
||||
};
|
||||
|
||||
const ImageDisplay: Component<ImageDisplayProps> = (props) => {
|
||||
const [hidden, setHidden] = createSignal(props.contentWarning.contentWarning);
|
||||
const url = () => new URL(props.url);
|
||||
const [hidden, setHidden] = createSignal(props.initialHidden);
|
||||
|
||||
return (
|
||||
<Show
|
||||
@@ -40,7 +24,7 @@ const ImageDisplay: Component<ImageDisplayProps> = (props) => {
|
||||
<a class="my-2 block" href={props.url} target="_blank" rel="noopener noreferrer">
|
||||
<img
|
||||
class="inline-block max-h-64 max-w-full rounded object-contain shadow hover:shadow-md"
|
||||
src={fixUrl(url())}
|
||||
src={fixUrl(new URL(props.url)).toString()}
|
||||
alt={props.url}
|
||||
/>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user