Files
vitfit-r2/site/public/workout.html
T
2026-06-10 21:34:22 -04:00

126 lines
4.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workout</title>
<style>
body, html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: #000;
font-family: Arial, sans-serif;
overflow: hidden; /* Prevents scrollbars */
}
.video-container {
display: grid;
width: 100%;
height: 100%;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
}
.video-item {
position: relative;
width: 100%;
height: 100%;
background-color: black;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.video-item video {
width: 100%;
height: 100%;
object-fit: cover;
}
.overlay {
position: absolute;
top: 10px;
left: 10px;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px 10px;
border-radius: 5px;
font-size: 100px;
}
</style>
</head>
<body>
<div class="video-container" id="videoContainer"></div>
<script>
document.addEventListener('DOMContentLoaded', async () => {
const videoContainer = document.getElementById('videoContainer');
const workoutId = new URLSearchParams(window.location.search).get('workoutId');
const token = localStorage.getItem('token');
if (!token) {
console.error('No token found');
videoContainer.innerHTML = "<p>Error: Unauthorized. Please log in.</p>";
return;
}
try {
const response = await fetch(`/workout-data/${workoutId}`, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Failed to fetch workout data: ${errorText}`);
}
const workout = await response.json();
const videos = [];
if (workout.video1) videos.push({ file: workout.video1, number: workout.number1 });
if (workout.video2) videos.push({ file: workout.video2, number: workout.number2 });
if (workout.video3) videos.push({ file: workout.video3, number: workout.number3 });
if (workout.video4) videos.push({ file: workout.video4, number: workout.number4 });
if (videos.length === 1) {
videoContainer.style.gridTemplateColumns = "1fr";
videoContainer.style.gridTemplateRows = "1fr";
} else if (videos.length === 2) {
videoContainer.style.gridTemplateColumns = "1fr 1fr";
videoContainer.style.gridTemplateRows = "1fr";
} else if (videos.length > 2) {
videoContainer.style.gridTemplateColumns = "1fr 1fr";
videoContainer.style.gridTemplateRows = "1fr 1fr";
}
videos.forEach((video) => {
if (video.file) {
const videoItem = document.createElement('div');
videoItem.className = 'video-item';
videoItem.innerHTML = `
<video src="/uploads/${video.file}" autoplay muted loop playsinline></video>
<div class="overlay">${video.number || ''}</div>
`;
videoContainer.appendChild(videoItem);
}
});
if (videoContainer.children.length === 0) {
videoContainer.innerHTML = "<p>No videos found for this workout.</p>";
}
setTimeout(() => {
location.reload();
}, 300000); // 7 minutes in milliseconds
} catch (error) {
console.error('Error fetching workout data:', error);
videoContainer.innerHTML = `<p>Error loading workout data: ${error.message}</p>`;
}
});
</script>
</body>
</html>