From e279fca60e3454ef986b463f3ea759c23dc2e60d Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 12 Feb 2021 00:42:28 +1300 Subject: [PATCH] Add comment explaining redirect method --- api/redirects.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/redirects.js b/api/redirects.js index 5a02ab3..e940798 100644 --- a/api/redirects.js +++ b/api/redirects.js @@ -4,6 +4,16 @@ const {redirect} = require("pinski/plugins") module.exports = [ { route: `/(${constants.regex.video_id})`, priority: -1, methods: ["GET"], code: async ({fill, url}) => { + /* + Why not URLSearchParams? + URLSearchParams is an unordered map, and URLs are more + aesthetic if the video ID is at the start of them. + This code makes the video ID always the first parameter, and + then adds on the `search` from the original URL, with the + leading ? replaced. + If the original URL had no parameters, there will be no + additional text added here. + */ return redirect(`/watch?v=${fill[0]}${url.search.replace(/^\?/, "&")}`, 301) } }