Skip to content

Commit

Permalink
fix(api): fix images not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Sep 3, 2021
1 parent 51b4d64 commit b5c83f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/pages/[...id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/user/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b5c83f9

Please sign in to comment.