From fe7c678955f61cb5584ebbbfebdcd4a5a61f33e1 Mon Sep 17 00:00:00 2001 From: McMistrzYT <56406996+McMistrzYT@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:52:26 +0100 Subject: [PATCH] fix authentication requirement for sub-pages --- Server/Source/Routes/Downloads.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Server/Source/Routes/Downloads.ts b/Server/Source/Routes/Downloads.ts index 7fc566f..ec5dd7d 100644 --- a/Server/Source/Routes/Downloads.ts +++ b/Server/Source/Routes/Downloads.ts @@ -5,6 +5,7 @@ import { CreateBlurl } from "../Modules/BLURL"; import { Song } from "../Schemas/Song"; import { RequireAuthentication } from "../Modules/Middleware"; import { UserPermissions } from "../Schemas/User"; +import path from "path"; const App = Router(); @@ -77,11 +78,18 @@ async (req, res) => { }); App.get("/:InternalID", +(req, res, next) => { + // send back index.html when the internal id is not a uuid - causes issues with reloading on sub-pages otherwise + if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(req.params.InternalID)) + return res.sendFile(path.join(process.cwd(), "dist", "index.html")); + + next(); +}, RequireAuthentication(), -async (req, res, next) => { +async (req, res) => { const SongData = await Song.findOne({ where: [ { ID: req.params.InternalID }, { PID: req.params.InternalID } ], relations: { Author: true } }); if (!SongData) - return next(); // trust me bro + return res.status(404).send("Track not found."); const IsPreview = SongData.ID != SongData.PID && req.params.InternalID == SongData.PID;