fix(api): fix images not showing

This commit is contained in:
diced 2021-09-02 21:46:10 -07:00
parent 51b4d64a93
commit b5c83f92e3
No known key found for this signature in database
GPG key ID: 85AB64C74535D76E
2 changed files with 12 additions and 6 deletions

View file

@ -9,12 +9,18 @@ export default function EmbeddedImage({ image, title, username, color, normal, e
const dataURL = (route: string) => `${route}/${image.file}`; const dataURL = (route: string) => `${route}/${image.file}`;
const updateImage = () => { const updateImage = () => {
const imageEl = document.getElementById('image_content') as HTMLImageElement;
const original = new Image; const original = new Image;
original.src = dataURL('/raw'); original.src = dataURL('/raw');
const imageEl = document.getElementById('image_content') as HTMLImageElement; if (original.width > innerWidth) {
imageEl.width = Math.floor(original.width * Math.min((innerHeight / original.height), (innerWidth / original.width))); imageEl.width = Math.floor(original.width * Math.min((innerHeight / original.height), (innerWidth / original.width)));
imageEl.height = innerHeight; imageEl.height = innerHeight;
} else {
imageEl.width = original.width;
imageEl.height = original.height;
}
}; };
if (typeof window !== 'undefined') window.onresize = () => updateImage(); if (typeof window !== 'undefined') window.onresize = () => updateImage();
@ -36,10 +42,10 @@ export default function EmbeddedImage({ image, title, username, color, normal, e
)} )}
<meta property='theme-color' content={color}/> <meta property='theme-color' content={color}/>
<meta property='og:url' content={dataURL(normal)} /> <meta property='og:url' content={dataURL(normal)} />
<meta property='og:image' content={dataURL('/raw')} />
<meta property='twitter:card' content='summary_large_image' />
</> </>
)} )}
<meta property='og:image' content={dataURL('/raw')} />
<meta property='twitter:card' content='summary_large_image' />
<title>{image.file}</title> <title>{image.file}</title>
</Head> </Head>
<Box <Box

View file

@ -54,7 +54,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
// @ts-ignore // @ts-ignore
images.map(image => image.url = `${config.uploader.route}/${image.file}`); images.map(image => image.url = `/raw/${image.file}`);
if (req.query.filter && req.query.filter === 'image') images = images.filter(x => x.mimetype.startsWith('image')); if (req.query.filter && req.query.filter === 'image') images = images.filter(x => x.mimetype.startsWith('image'));
return res.json(req.query.paged ? chunk(images, 16) : images); return res.json(req.query.paged ? chunk(images, 16) : images);