async function getRedirectUrl(url: string) { const response = await fetch(url, { method: 'GET', redirect: 'manual' // Prevents automatic following of redirects }); if (response.status === 301 || response.status === 302) { const redirectUrl = response.headers.get('Location'); if (!redirectUrl) { throw new Error('Redirect location header not found, null'); } return redirectUrl; } throw new Error(`Unexpected status code: ${response.status}`); } export const getPlatformVersion = async ( host: string ): Promise => { try { const threekitPlayerUrl = `https://${host}/app/js/threekit-player.js`; const redirectPlayerUrl = await getRedirectUrl(threekitPlayerUrl); const regex = /(?\d{4})-(?\d{2})-(?\d{2})-(?\d{2})-(?\d{2})-(?\d{2})(?=\.js$)/; const match = redirectPlayerUrl.match(regex) as RegExpMatchArray; if (match) { const { year, month, day, hour, minute, second } = match.groups as { year: string; month: string; day: string; hour: string; minute: string; second: string; }; return `${year}-${month}-${day}T${hour}:${minute}:${second}`; } } catch (error) { console.error(error); } return undefined; };