fix(api): new way to handle non-embedded images to overwrite nextjs & supports discord now
This commit is contained in:
parent
cb40559e49
commit
b29bfeb8b1
1 changed files with 14 additions and 9 deletions
|
@ -4,6 +4,7 @@ import { GetServerSideProps } from 'next';
|
||||||
import { Box } from '@material-ui/core';
|
import { Box } from '@material-ui/core';
|
||||||
import config from 'lib/config';
|
import config from 'lib/config';
|
||||||
import prisma from 'lib/prisma';
|
import prisma from 'lib/prisma';
|
||||||
|
import getFile from '../../server/static';
|
||||||
|
|
||||||
export default function EmbeddedImage({ image, title, username, color, normal, embed }) {
|
export default function EmbeddedImage({ image, title, username, color, normal, embed }) {
|
||||||
const dataURL = (route: string) => `${route}/${image.file}`;
|
const dataURL = (route: string) => `${route}/${image.file}`;
|
||||||
|
@ -80,10 +81,13 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
|
|
||||||
if (!image) return { notFound: true };
|
if (!image) return { notFound: true };
|
||||||
|
|
||||||
if (!image.embed) return { redirect: {
|
if (!image.embed) {
|
||||||
permanent: true,
|
const data = await getFile(config.uploader.directory, id);
|
||||||
destination: '/r/' + image.file,
|
if (!data) return { notFound: true };
|
||||||
} };
|
|
||||||
|
context.res.end(data);
|
||||||
|
return { props: {} };
|
||||||
|
};
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
select: {
|
select: {
|
||||||
|
@ -96,11 +100,12 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!image.mimetype.startsWith('image')) return {
|
if (!image.mimetype.startsWith('image')) {
|
||||||
redirect: {
|
const data = await getFile(config.uploader.directory, id);
|
||||||
permanent: true,
|
if (!data) return { notFound: true };
|
||||||
destination: '/r/' + image.file,
|
|
||||||
}
|
context.res.end(data);
|
||||||
|
return { props: {} };
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue