434 lines
14 KiB
HTML
434 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>PicUpper Gallery</title>
|
|
<style>
|
|
:root {
|
|
--bg-color: #1a1a1a;
|
|
--card-bg: #2d2d2d;
|
|
--text-color: #e0e0e0;
|
|
--accent-color: #3b82f6;
|
|
--error-color: #ef4444;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
margin: 0;
|
|
padding: 20px;
|
|
}
|
|
|
|
h1,
|
|
h2,
|
|
h3 {
|
|
color: #fff;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
/* Layout */
|
|
.controls {
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-bottom: 20px;
|
|
background: var(--card-bg);
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
select {
|
|
background: #404040;
|
|
color: white;
|
|
padding: 8px;
|
|
border: 1px solid #555;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
/* Grid */
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
|
/* Slightly wider for scrubbing */
|
|
gap: 15px;
|
|
}
|
|
|
|
.card {
|
|
background: var(--card-bg);
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
transition: transform 0.2s;
|
|
cursor: pointer;
|
|
position: relative;
|
|
}
|
|
|
|
.card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
.card img {
|
|
width: 100%;
|
|
height: 180px;
|
|
/* Taller for better view */
|
|
object-fit: cover;
|
|
display: block;
|
|
pointer-events: none;
|
|
/* Let clicks pass to card */
|
|
}
|
|
|
|
.card-info {
|
|
padding: 10px;
|
|
font-size: 0.9rem;
|
|
color: #ccc;
|
|
background: rgba(0, 0, 0, 0.6);
|
|
position: absolute;
|
|
bottom: 0;
|
|
width: 100%;
|
|
}
|
|
|
|
/* Modal */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.9);
|
|
justify-content: center;
|
|
align-items: center;
|
|
z-index: 100;
|
|
}
|
|
|
|
.modal.active {
|
|
display: flex;
|
|
}
|
|
|
|
.modal img {
|
|
max-width: 90%;
|
|
max-height: 90vh;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.modal-close {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 30px;
|
|
color: white;
|
|
font-size: 3rem;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Loading */
|
|
.loader {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 20px;
|
|
width: 100%;
|
|
}
|
|
|
|
.empty {
|
|
text-align: center;
|
|
color: #888;
|
|
margin-top: 50px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h1>📷 PicUpper Gallery</h1>
|
|
|
|
<div class="controls">
|
|
<div>
|
|
<label>Camera:</label>
|
|
<select id="cameraSelect">
|
|
<!-- Populated via API -->
|
|
<option value="">Loading cameras...</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label>Date:</label>
|
|
<select id="dateSelect" disabled>
|
|
<option value="">Select a camera first</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div style="margin-left: auto;">
|
|
<button id="refreshBtn" onclick="loadImages()">Refresh</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="loader" class="loader">Loading images...</div>
|
|
<div id="grid" class="grid"></div>
|
|
<div id="empty" class="empty">Select a camera and date to view images</div>
|
|
</div>
|
|
|
|
<!-- Lightbox Modal -->
|
|
<div id="modal" class="modal" onclick="closeModal()">
|
|
<span class="modal-close">×</span>
|
|
<img id="modalImg" src="" alt="Full size">
|
|
</div>
|
|
|
|
<script>
|
|
// State
|
|
const state = {
|
|
cameras: [],
|
|
selectedCamera: localStorage.getItem('lastCamera') || '',
|
|
selectedDate: localStorage.getItem('lastDate') || ''
|
|
};
|
|
|
|
// DOM Elements
|
|
const cameraSelect = document.getElementById('cameraSelect');
|
|
const dateSelect = document.getElementById('dateSelect');
|
|
const grid = document.getElementById('grid');
|
|
const loader = document.getElementById('loader');
|
|
const emptyMsg = document.getElementById('empty');
|
|
const modal = document.getElementById('modal');
|
|
const modalImg = document.getElementById('modalImg');
|
|
|
|
// Init
|
|
async function init() {
|
|
if (!await checkAuth()) return; // Simple check if API key needed (UI is public read locally)
|
|
await loadCameras();
|
|
}
|
|
|
|
// Authenticated? (For this internal tool, we assume read access is open or basic auth handled by nginx if tailored later)
|
|
async function checkAuth() {
|
|
// Since we exposed uploads and api publicly in server.js, try listing cameras via API
|
|
// NOTE: The API requires authentication. For this web UI to work publicly,
|
|
// we either need to loosen auth for GET requests or prompt for API key.
|
|
// Let's implement an API Key prompt if fetch fails with 401.
|
|
|
|
const apiKey = localStorage.getItem('apiKey');
|
|
if (!apiKey) {
|
|
const key = prompt("Enter API Key to view gallery:");
|
|
if (key) {
|
|
localStorage.setItem('apiKey', key);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function getHeaders() {
|
|
return { 'X-API-Key': localStorage.getItem('apiKey') || '' };
|
|
}
|
|
|
|
async function loadCameras() {
|
|
try {
|
|
const res = await fetch('cameras', { headers: getHeaders() });
|
|
if (res.status === 401) {
|
|
localStorage.removeItem('apiKey');
|
|
location.reload();
|
|
return;
|
|
}
|
|
const data = await res.json();
|
|
state.cameras = data.cameras;
|
|
|
|
cameraSelect.innerHTML = '<option value="">Select Camera</option>';
|
|
state.cameras.forEach(cam => {
|
|
const opt = document.createElement('option');
|
|
opt.value = cam;
|
|
opt.textContent = cam;
|
|
if (cam === state.selectedCamera) opt.selected = true;
|
|
cameraSelect.appendChild(opt);
|
|
});
|
|
|
|
cameraSelect.disabled = false;
|
|
|
|
if (state.selectedCamera) {
|
|
loadDates(state.selectedCamera);
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
cameraSelect.innerHTML = '<option>Error loading cameras</option>';
|
|
}
|
|
}
|
|
|
|
async function loadDates(cameraId) {
|
|
try {
|
|
dateSelect.innerHTML = '<option>Loading...</option>';
|
|
dateSelect.disabled = true;
|
|
|
|
const res = await fetch(`cameras/${cameraId}/dates`, { headers: getHeaders() });
|
|
|
|
const data = await res.json();
|
|
|
|
dateSelect.innerHTML = '<option value="">Select Date</option>';
|
|
data.dates.forEach(date => {
|
|
const opt = document.createElement('option');
|
|
opt.value = date;
|
|
opt.textContent = date;
|
|
if (date === state.selectedDate) opt.selected = true;
|
|
dateSelect.appendChild(opt);
|
|
});
|
|
|
|
dateSelect.disabled = false;
|
|
|
|
if (state.selectedDate && data.dates.includes(state.selectedDate)) {
|
|
loadImages();
|
|
} else if (data.dates.length > 0) {
|
|
// Auto select newest
|
|
dateSelect.value = data.dates[0];
|
|
state.selectedDate = data.dates[0];
|
|
loadImages();
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
dateSelect.innerHTML = '<option>Error loading dates</option>';
|
|
}
|
|
}
|
|
|
|
async function loadImages() {
|
|
const cameraId = cameraSelect.value;
|
|
const dateStr = dateSelect.value; // YYYY-MM-DD
|
|
|
|
if (!cameraId || !dateStr) return;
|
|
|
|
// Update state/localstorage
|
|
state.selectedCamera = cameraId;
|
|
state.selectedDate = dateStr;
|
|
localStorage.setItem('lastCamera', cameraId);
|
|
localStorage.setItem('lastDate', dateStr);
|
|
|
|
loader.style.display = 'block';
|
|
grid.innerHTML = '';
|
|
emptyMsg.style.display = 'none';
|
|
|
|
const [year, month, day] = dateStr.split('-');
|
|
|
|
try {
|
|
const res = await fetch(`cameras/${cameraId}/${year}/${month}/${day}`);
|
|
const data = await res.json();
|
|
|
|
loader.style.display = 'none';
|
|
|
|
if (data.images.length === 0) {
|
|
emptyMsg.style.display = 'block';
|
|
return;
|
|
}
|
|
|
|
// Group by hour
|
|
const hours = {};
|
|
data.images.forEach(img => {
|
|
let h = '00';
|
|
try {
|
|
const match = img.timestamp.match(/(\d{2})[-:](\d{2})[-:](\d{2})/);
|
|
if (match) {
|
|
h = match[1];
|
|
} else {
|
|
const d = new Date(img.timestamp);
|
|
if (!isNaN(d.getTime())) h = String(d.getHours()).padStart(2, '0');
|
|
}
|
|
} catch (e) { }
|
|
|
|
if (!hours[h]) hours[h] = [];
|
|
hours[h].push(img);
|
|
});
|
|
|
|
// Render Hour Cards
|
|
Object.keys(hours).sort().forEach(hour => {
|
|
const group = hours[hour];
|
|
// Sort images in this hour
|
|
group.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
|
|
const card = document.createElement('div');
|
|
card.className = 'card';
|
|
card.dataset.idx = 0; // Current viewed index
|
|
|
|
const thumb = document.createElement('img');
|
|
thumb.src = group[0].thumbnailUrl;
|
|
|
|
const info = document.createElement('div');
|
|
info.className = 'card-info';
|
|
info.textContent = `${hour}:00 (${group.length} pics)`;
|
|
|
|
// Hover scrubbing logic
|
|
card.onmousemove = (e) => {
|
|
if (group.length <= 1) return;
|
|
|
|
const rect = card.getBoundingClientRect();
|
|
const x = e.clientX - rect.left;
|
|
const width = rect.width;
|
|
const percent = Math.max(0, Math.min(1, x / width));
|
|
const index = Math.floor(percent * group.length);
|
|
const safeIndex = Math.min(group.length - 1, Math.max(0, index));
|
|
|
|
if (card.dataset.idx != safeIndex) {
|
|
thumb.src = group[safeIndex].thumbnailUrl;
|
|
card.dataset.idx = safeIndex;
|
|
info.textContent = `${hour}:00 - ` + getPrettyTime(group[safeIndex].timestamp);
|
|
}
|
|
};
|
|
|
|
card.onmouseleave = () => {
|
|
// Optional: could reset here
|
|
};
|
|
|
|
card.onclick = () => {
|
|
const idx = parseInt(card.dataset.idx || '0');
|
|
openModal(group[idx].url);
|
|
};
|
|
|
|
card.appendChild(thumb);
|
|
card.appendChild(info);
|
|
grid.appendChild(card);
|
|
});
|
|
|
|
} catch (err) {
|
|
loader.style.display = 'none';
|
|
console.error(err);
|
|
grid.innerHTML = '<div style="color:red">Error loading images</div>';
|
|
}
|
|
}
|
|
|
|
function getPrettyTime(ts) {
|
|
const parts = ts.match(/(\d{2})[-:](\d{2})[-:](\d{2})/);
|
|
if (parts) return `${parts[1]}:${parts[2]}:${parts[3]}`;
|
|
return ts;
|
|
}
|
|
|
|
// Modal
|
|
function openModal(src) {
|
|
modalImg.src = src;
|
|
modal.classList.add('active');
|
|
}
|
|
|
|
function closeModal() {
|
|
modal.classList.remove('active');
|
|
setTimeout(() => modalImg.src = '', 200);
|
|
}
|
|
|
|
// Listeners
|
|
cameraSelect.addEventListener('change', (e) => {
|
|
state.selectedCamera = e.target.value;
|
|
if (state.selectedCamera) loadDates(state.selectedCamera);
|
|
else dateSelect.disabled = true;
|
|
});
|
|
|
|
dateSelect.addEventListener('change', (e) => {
|
|
state.selectedDate = e.target.value;
|
|
if (state.selectedDate) loadImages();
|
|
});
|
|
|
|
// Start
|
|
init();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |