mirror of
				https://git.sr.ht/~cadence/cloudtube
				synced 2025-10-27 19:59:08 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			737 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			737 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const constants = require("../utils/constants")
 | |
| const {redirect} = require("pinski/plugins")
 | |
| 
 | |
| module.exports = [
 | |
| 	{
 | |
| 		route: `/(?:watch/|w/|v/|shorts/|e/)?(${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)
 | |
| 		}
 | |
| 	}
 | |
| ]
 | 
