Files
vitfit-r2/V2/app/public/upload-video.html
T
2026-06-16 07:17:49 -04:00

149 lines
5.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Video — VitFit</title>
<link rel="manifest" href="/manifest.json">
<link rel="stylesheet" href="/styles/base.css">
<link rel="stylesheet" href="/styles/layout.css">
<link rel="stylesheet" href="/styles/components.css">
</head>
<body>
<header class="banner">
<button class="banner-hamburger" id="nav-hamburger" aria-label="Menu">&#9776;</button>
<img id="banner-logo" alt="Logo" style="display:none;height:36px;">
<span id="app-name" class="banner-title">VitFit</span>
</header>
<div class="drawer-scrim" id="drawer-scrim"></div>
<nav class="nav-drawer" id="nav-drawer"><ul class="nav-list" id="nav-list"></ul></nav>
<main class="main-content">
<div class="page-header">
<h1 class="page-title">Upload Video</h1>
<a href="/videos.html" class="btn btn-ghost">Back to Videos</a>
</div>
<div class="card" style="max-width:600px;">
<form id="upload-form" novalidate>
<div class="form-group">
<label class="form-label" for="video-file">Video File <span class="required">*</span></label>
<input class="form-input" type="file" id="video-file" accept="video/*" required>
<p class="form-hint">MP4 recommended. Max 2GB.</p>
</div>
<div class="form-group">
<label class="form-label" for="description">Description <span class="required">*</span></label>
<input class="form-input" type="text" id="description" maxlength="200" required>
</div>
<div class="form-group">
<label class="form-label" for="category-id">Category</label>
<select class="form-select" id="category-id">
<option value="">None</option>
</select>
</div>
<div class="form-group">
<label class="form-label" for="thumbnail">Thumbnail (optional)</label>
<input class="form-input" type="file" id="thumbnail" accept="image/*">
</div>
<div id="progress-wrap" style="display:none;" class="form-group">
<div class="progress-bar-track">
<div class="progress-bar-fill" id="progress-bar" style="width:0%"></div>
</div>
<p id="progress-label" class="form-hint">0%</p>
</div>
<div id="upload-error" class="form-error" style="display:none;"></div>
<button class="btn btn-primary" type="submit" id="upload-btn">Upload</button>
</form>
</div>
</main>
<div id="session-expired-overlay" class="session-expired-overlay">
<div class="session-expired-box">
<p>Your session has expired.</p>
<a href="/" class="btn btn-primary">Sign In Again</a>
</div>
</div>
<script src="/js/core.js"></script>
<script>
document.addEventListener('DOMContentLoaded', async () => {
await Page.init(['Owner', 'Coach']);
// Load categories
try {
const res = await Api.get('/api/v1/categories');
if (res.ok) {
const { data } = await res.json();
const sel = document.getElementById('category-id');
data.forEach(c => {
const opt = document.createElement('option');
opt.value = c.name; opt.textContent = c.name;
sel.appendChild(opt);
});
}
} catch {}
document.getElementById('upload-form').addEventListener('submit', async (e) => {
e.preventDefault();
const errEl = document.getElementById('upload-error');
const btn = document.getElementById('upload-btn');
const progWrap = document.getElementById('progress-wrap');
const progBar = document.getElementById('progress-bar');
const progLabel = document.getElementById('progress-label');
errEl.style.display = 'none';
const file = document.getElementById('video-file').files[0];
if (!file) { errEl.textContent = 'Please select a video.'; errEl.style.display = 'block'; return; }
const fd = new FormData();
fd.append('video', file);
fd.append('description', document.getElementById('description').value.trim());
const catId = document.getElementById('category-id').value;
if (catId) fd.append('category', catId);
const thumb = document.getElementById('thumbnail').files[0];
if (thumb) fd.append('thumbnail', thumb);
btn.disabled = true; btn.textContent = 'Uploading…';
progWrap.style.display = 'block';
// Use XHR for progress
const jwt = Auth.getJwt();
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/v1/videos');
if (jwt) xhr.setRequestHeader('Authorization', `Bearer ${jwt}`);
xhr.upload.addEventListener('progress', (ev) => {
if (ev.lengthComputable) {
const pct = Math.round(ev.loaded / ev.total * 100);
progBar.style.width = pct + '%';
progLabel.textContent = pct + '%';
}
});
xhr.addEventListener('load', () => {
if (xhr.status >= 200 && xhr.status < 300) {
toast('Video uploaded successfully!', 'success');
setTimeout(() => { window.location.href = '/videos.html'; }, 1200);
} else {
let msg = 'Upload failed.';
try { msg = JSON.parse(xhr.responseText).message || msg; } catch {}
errEl.textContent = msg; errEl.style.display = 'block';
btn.disabled = false; btn.textContent = 'Upload';
}
});
xhr.addEventListener('error', () => {
errEl.textContent = 'Network error during upload.'; errEl.style.display = 'block';
btn.disabled = false; btn.textContent = 'Upload';
});
xhr.send(fd);
});
});
</script>
</body>
</html>