index.js
1 // This file is a placeholder to ensure that requests to /live/index.js are redirected to /app/index.js 2 // The actual redirection is handled by the index.html file in this directory 3 console.warn('This file should not be executed directly. Redirecting to the correct location...'); 4 5 try { 6 // Create a URL object to properly handle the redirection while preserving query parameters 7 const currentUrl = new URL(window.location.href); 8 9 // Set a flag in localStorage to indicate we're in livestream mode 10 localStorage.setItem('daokotube_livestream_mode', 'true'); 11 12 // Get the date parameter if it exists 13 const urlParams = new URLSearchParams(currentUrl.search); 14 const dateParam = urlParams.get('v'); 15 16 // If we have a date parameter, store it for later use 17 if (dateParam && /^\d{8}$/.test(dateParam)) { 18 localStorage.setItem('daokotube_livestream_date', dateParam); 19 console.info(`Livestream date parameter detected: ${dateParam}`); 20 } else { 21 // If no specific date requested, we'll select a random entry later 22 localStorage.setItem('daokotube_livestream_random', 'true'); 23 console.info('No specific livestream requested, will select random entry'); 24 } 25 26 // Replace /live/ with /app/ in the path 27 const newPath = currentUrl.pathname.replace(/^\/live(\/|$)/, '/app$1'); 28 29 // Update the pathname while preserving the query parameters 30 currentUrl.pathname = newPath; 31 32 // Redirect to the new URL 33 console.info(`Redirecting from ${window.location.pathname} to ${newPath} (with query params: ${currentUrl.search})`); 34 window.location.href = currentUrl.toString(); 35 } catch (error) { 36 // Fallback to simple string replacement if URL parsing fails 37 console.error('Error during URL redirection:', error); 38 localStorage.setItem('daokotube_livestream_mode', 'true'); 39 window.location.href = window.location.href.replace(/^(.*?)\/live\//, '$1/app/'); 40 }