diff --git a/src/pages/[...id].tsx b/src/pages/[...id].tsx index 3eb2c21..63dd679 100644 --- a/src/pages/[...id].tsx +++ b/src/pages/[...id].tsx @@ -33,11 +33,11 @@ export default function EmbeddedImage({ image, user, pass }) { const imageEl = document.getElementById('image_content') as HTMLImageElement; const img = new Image(); - img.addEventListener('load', function() { + img.addEventListener('load', function () { if (this.naturalWidth > innerWidth) imageEl.width = Math.floor(this.naturalWidth * Math.min((innerHeight / this.naturalHeight), (innerWidth / this.naturalWidth))); else imageEl.width = this.naturalWidth; }); - + img.src = url || dataURL('/r'); if (url) { imageEl.src = url; @@ -95,11 +95,13 @@ export default function EmbeddedImage({ image, user, pass }) { } export const getServerSideProps: GetServerSideProps = async (context) => { - const id = context.params.id[1]; const route = context.params.id[0]; - const routes = [config.uploader.route.substring(1), config.urls.route.substring(1)]; - if (!routes.includes(route)) return { notFound: true }; - if (route === routes[1]) { + const serve_on_root = /(^[^\\.]+\.[^\\.]+)/.test(route); + + 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({ where: { 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({ where: { OR: [ @@ -184,5 +186,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => { pass, }, }; + } else { + return { notFound: true }; } }; diff --git a/src/server/server.ts b/src/server/server.ts index 90907cc..3f39e5c 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -72,6 +72,7 @@ export default class Server { ], }, }); + console.log(image); if (!image) await this.rawFile(req, res, params.id); diff --git a/tsconfig.json b/tsconfig.json index 8d794cd..67e302a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,11 +20,20 @@ "noEmit": true, "baseUrl": "src", "paths": { - "components/*": ["components/*"], - "hooks/*": ["lib/hooks/*"], - "middleware/*": ["lib/middleware/*"], - "lib/*": ["lib/*"] - } + "components/*": [ + "components/*" + ], + "hooks/*": [ + "lib/hooks/*" + ], + "middleware/*": [ + "lib/middleware/*" + ], + "lib/*": [ + "lib/*" + ] + }, + "incremental": true }, "include": [ "next-env.d.ts",