fix(api): fix images not showing
This commit is contained in:
parent
51b4d64a93
commit
b5c83f92e3
2 changed files with 12 additions and 6 deletions
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue