From b5c83f92e3beaf0735bf04b06427fa4682c844d4 Mon Sep 17 00:00:00 2001 From: diced Date: Thu, 2 Sep 2021 21:46:10 -0700 Subject: [PATCH] fix(api): fix images not showing --- src/pages/[...id].tsx | 16 +++++++++++----- src/pages/api/user/images.ts | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pages/[...id].tsx b/src/pages/[...id].tsx index 07edb00..6bd44df 100644 --- a/src/pages/[...id].tsx +++ b/src/pages/[...id].tsx @@ -9,12 +9,18 @@ export default function EmbeddedImage({ image, title, username, color, normal, e const dataURL = (route: string) => `${route}/${image.file}`; const updateImage = () => { + const imageEl = document.getElementById('image_content') as HTMLImageElement; + const original = new Image; original.src = dataURL('/raw'); - const imageEl = document.getElementById('image_content') as HTMLImageElement; - imageEl.width = Math.floor(original.width * Math.min((innerHeight / original.height), (innerWidth / original.width))); - imageEl.height = innerHeight; + if (original.width > innerWidth) { + imageEl.width = Math.floor(original.width * Math.min((innerHeight / original.height), (innerWidth / original.width))); + imageEl.height = innerHeight; + } else { + imageEl.width = original.width; + imageEl.height = original.height; + } }; if (typeof window !== 'undefined') window.onresize = () => updateImage(); @@ -36,10 +42,10 @@ export default function EmbeddedImage({ image, title, username, color, normal, e )} - - )} + + {image.file} 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')); return res.json(req.query.paged ? chunk(images, 16) : images);