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 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
)}
<meta property='theme-color' content={color}/>
<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>
</Head>
<Box

View file

@ -54,7 +54,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
// @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'));
return res.json(req.query.paged ? chunk(images, 16) : images);