fix(api): password protected images wont show up on root

This commit is contained in:
diced 2022-06-17 15:35:29 -07:00
parent 2a402f77b5
commit 2ddf8c0cdb
No known key found for this signature in database
GPG key ID: 370BD1BA142842D1
3 changed files with 26 additions and 12 deletions

View file

@ -95,11 +95,13 @@ export default function EmbeddedImage({ image, user, pass }) {
} }
export const getServerSideProps: GetServerSideProps = async (context) => { export const getServerSideProps: GetServerSideProps = async (context) => {
const id = context.params.id[1];
const route = context.params.id[0]; const route = context.params.id[0];
const routes = [config.uploader.route.substring(1), config.urls.route.substring(1)]; const serve_on_root = /(^[^\\.]+\.[^\\.]+)/.test(route);
if (!routes.includes(route)) return { notFound: true };
if (route === routes[1]) { const id = serve_on_root ? route : context.params.id[1];
const uploader_route = config.uploader.route.substring(1);
if (route === config.urls.route.substring(1)) {
const url = await prisma.url.findFirst({ const url = await prisma.url.findFirst({
where: { where: {
OR: [ OR: [
@ -121,7 +123,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
}, },
}; };
} else { } else if (uploader_route === '' ? /(^[^\\.]+\.[^\\.]+)/.test(route) : route === uploader_route) {
const image = await prisma.image.findFirst({ const image = await prisma.image.findFirst({
where: { where: {
OR: [ OR: [
@ -184,5 +186,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
pass, pass,
}, },
}; };
} else {
return { notFound: true };
} }
}; };

View file

@ -72,6 +72,7 @@ export default class Server {
], ],
}, },
}); });
console.log(image);
if (!image) await this.rawFile(req, res, params.id); if (!image) await this.rawFile(req, res, params.id);

View file

@ -20,11 +20,20 @@
"noEmit": true, "noEmit": true,
"baseUrl": "src", "baseUrl": "src",
"paths": { "paths": {
"components/*": ["components/*"], "components/*": [
"hooks/*": ["lib/hooks/*"], "components/*"
"middleware/*": ["lib/middleware/*"], ],
"lib/*": ["lib/*"] "hooks/*": [
} "lib/hooks/*"
],
"middleware/*": [
"lib/middleware/*"
],
"lib/*": [
"lib/*"
]
},
"incremental": true
}, },
"include": [ "include": [
"next-env.d.ts", "next-env.d.ts",