1
0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2024-11-10 02:27:29 +00:00

Add comment explaining redirect method

This commit is contained in:
Cadence Ember 2021-02-12 00:42:28 +13:00
parent 4332d3043f
commit e279fca60e
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17

View File

@ -4,6 +4,16 @@ const {redirect} = require("pinski/plugins")
module.exports = [ module.exports = [
{ {
route: `/(${constants.regex.video_id})`, priority: -1, methods: ["GET"], code: async ({fill, url}) => { 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) return redirect(`/watch?v=${fill[0]}${url.search.replace(/^\?/, "&")}`, 301)
} }
} }