feat: Implement image fetching and storage system
Some checks failed
Deploy to BeePC / deploy (push) Has been cancelled
Some checks failed
Deploy to BeePC / deploy (push) Has been cancelled
- Add image-fetcher module for downloading and saving images from various sources. - Create storage module for managing image files, including downloading, verifying integrity, and cleaning up orphaned files. - Develop gallery HTML page for displaying images with sorting and filtering options. - Set up RESTful API routes for image management, including fetching, adding tags, and deleting images. - Introduce setup script for initializing the database and configuring image sources. - Implement a batch process for verifying image integrity and cleaning up old images. - Add setup batch script for easy installation and configuration of the image storage system.
This commit is contained in:
587
public/gallery.html
Normal file
587
public/gallery.html
Normal file
@@ -0,0 +1,587 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>HomeBase Image Gallery</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
color: white;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1em;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.controls {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-bottom: 30px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.controls label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.controls select,
|
||||
.controls input {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
|
||||
.controls select {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.stats {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 15px 20px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
flex-wrap: wrap;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 0.9em;
|
||||
color: #666;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.timeline {
|
||||
position: relative;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.timeline::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 3px;
|
||||
height: 100%;
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.timeline-item {
|
||||
margin-bottom: 40px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.timeline-item:nth-child(odd) .timeline-content {
|
||||
margin-left: 0;
|
||||
margin-right: auto;
|
||||
width: calc(50% - 20px);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.timeline-item:nth-child(even) .timeline-content {
|
||||
margin-left: auto;
|
||||
margin-right: 0;
|
||||
width: calc(50% - 20px);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.timeline-marker {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 0;
|
||||
transform: translateX(-50%);
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background: white;
|
||||
border: 3px solid #667eea;
|
||||
border-radius: 50%;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.timeline-content:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.timeline-content img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
max-height: 300px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.timeline-timestamp {
|
||||
font-weight: 600;
|
||||
color: #667eea;
|
||||
font-size: 0.95em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.timeline-tags {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.timeline-tag {
|
||||
display: inline-block;
|
||||
background: #f0f0f0;
|
||||
color: #555;
|
||||
padding: 4px 10px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
.timeline-tag.active {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.timeline-size {
|
||||
font-size: 0.85em;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.loading {
|
||||
text-align: center;
|
||||
color: white;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ff6b6b;
|
||||
color: white;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.empty {
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.timeline::before {
|
||||
left: 20px;
|
||||
}
|
||||
|
||||
.timeline-marker {
|
||||
left: 20px;
|
||||
}
|
||||
|
||||
.timeline-item:nth-child(odd) .timeline-content,
|
||||
.timeline-item:nth-child(even) .timeline-content {
|
||||
width: calc(100% - 50px);
|
||||
margin-left: 50px;
|
||||
margin-right: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 1.8em;
|
||||
}
|
||||
|
||||
.controls {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.stats {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
animation: fadeIn 0.3s;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: relative;
|
||||
margin: auto;
|
||||
padding: 0;
|
||||
max-width: 90vw;
|
||||
max-height: 90vh;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.modal-content img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.modal-info {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 0 0 8px 8px;
|
||||
}
|
||||
|
||||
.close {
|
||||
position: absolute;
|
||||
right: 20px;
|
||||
top: 20px;
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
z-index: 1001;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
background: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>📸 Image Timeline</h1>
|
||||
<p>Browse your captured images chronologically</p>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<label>
|
||||
Sort by:
|
||||
<select id="sortSelect">
|
||||
<option value="newest">Newest First</option>
|
||||
<option value="oldest">Oldest First</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Filter by tag:
|
||||
<select id="tagSelect">
|
||||
<option value="">All Tags</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Refresh:
|
||||
<input type="checkbox" id="autoRefresh" unchecked>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="stats">
|
||||
<div class="stat">
|
||||
<span class="stat-label">Total Images</span>
|
||||
<span class="stat-value" id="totalCount">0</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">Total Storage</span>
|
||||
<span class="stat-value" id="totalSize">0 GB</span>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<span class="stat-label">Last Updated</span>
|
||||
<span class="stat-value" id="lastUpdated">--:--</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="loading" class="loading">Loading images...</div>
|
||||
<div id="error" class="error" style="display:none;"></div>
|
||||
<div class="timeline" id="timeline" style="display:none;"></div>
|
||||
<div class="empty" id="empty" style="display:none;">No images found. Start fetching to see images here!</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal for full image view -->
|
||||
<div id="imageModal" class="modal">
|
||||
<div class="modal-content">
|
||||
<span class="close">×</span>
|
||||
<img id="modalImage" src="" alt="">
|
||||
<div class="modal-info" id="modalInfo"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const API_BASE = '';
|
||||
let allImages = [];
|
||||
let allTags = [];
|
||||
let refreshInterval = null;
|
||||
|
||||
const timeline = document.getElementById('timeline');
|
||||
const loading = document.getElementById('loading');
|
||||
const error = document.getElementById('error');
|
||||
const empty = document.getElementById('empty');
|
||||
const sortSelect = document.getElementById('sortSelect');
|
||||
const tagSelect = document.getElementById('tagSelect');
|
||||
const autoRefresh = document.getElementById('autoRefresh');
|
||||
const modal = document.getElementById('imageModal');
|
||||
const closeBtn = document.querySelector('.close');
|
||||
|
||||
function formatDate(dateString) {
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
|
||||
}
|
||||
|
||||
function formatSize(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
async function loadImages() {
|
||||
try {
|
||||
loading.style.display = 'block';
|
||||
error.style.display = 'none';
|
||||
timeline.style.display = 'none';
|
||||
empty.style.display = 'none';
|
||||
|
||||
// Fetch images
|
||||
const response = await fetch(`${API_BASE}/api/images?pageSize=999`);
|
||||
if (!response.ok) throw new Error('Failed to fetch images');
|
||||
const data = await response.json();
|
||||
allImages = data.images || [];
|
||||
|
||||
// Fetch tags
|
||||
const tagsResponse = await fetch(`${API_BASE}/api/tags`);
|
||||
const tagsData = await tagsResponse.json();
|
||||
allTags = tagsData.tags || [];
|
||||
|
||||
// Fetch stats
|
||||
const statsResponse = await fetch(`${API_BASE}/api/stats`);
|
||||
const statsData = statsResponse.ok ? await statsResponse.json() : null;
|
||||
if (statsData) {
|
||||
document.getElementById('totalCount').textContent = statsData.stats.imageCount || allImages.length;
|
||||
document.getElementById('totalSize').textContent = statsData.stats.totalSizeGB + ' GB' || '0 GB';
|
||||
document.getElementById('lastUpdated').textContent = new Date().toLocaleTimeString();
|
||||
}
|
||||
|
||||
// Update tag filter
|
||||
updateTagFilter();
|
||||
|
||||
// Render images
|
||||
renderTimeline();
|
||||
|
||||
loading.style.display = 'none';
|
||||
} catch (err) {
|
||||
console.error('Error loading images:', err);
|
||||
error.style.display = 'block';
|
||||
error.textContent = 'Error loading images: ' + err.message;
|
||||
loading.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function updateTagFilter() {
|
||||
const currentValue = tagSelect.value;
|
||||
tagSelect.innerHTML = '<option value="">All Tags</option>';
|
||||
allTags.forEach(tag => {
|
||||
const option = document.createElement('option');
|
||||
option.value = tag;
|
||||
option.textContent = tag;
|
||||
tagSelect.appendChild(option);
|
||||
});
|
||||
tagSelect.value = currentValue;
|
||||
}
|
||||
|
||||
function renderTimeline() {
|
||||
// Filter images
|
||||
const selectedTag = tagSelect.value;
|
||||
let filtered = allImages;
|
||||
if (selectedTag) {
|
||||
filtered = allImages.filter(img =>
|
||||
img.tags && img.tags.includes(selectedTag)
|
||||
);
|
||||
}
|
||||
|
||||
// Sort images
|
||||
const sorted = [...filtered];
|
||||
if (sortSelect.value === 'oldest') {
|
||||
sorted.reverse();
|
||||
}
|
||||
|
||||
// Clear timeline
|
||||
timeline.innerHTML = '';
|
||||
|
||||
if (sorted.length === 0) {
|
||||
empty.style.display = 'block';
|
||||
timeline.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
// Add items
|
||||
sorted.forEach(image => {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'timeline-item';
|
||||
|
||||
const content = document.createElement('div');
|
||||
content.className = 'timeline-content';
|
||||
content.onclick = () => showModal(image);
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = `${API_BASE}/api/images/${image.id}/download`;
|
||||
img.onerror = () => img.src = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="100" height="100"%3E%3Crect fill="%23ccc" width="100" height="100"/%3E%3Ctext x="50" y="50" text-anchor="middle" dy=".3em" fill="%23999" font-size="14"%3EImage Error%3C/text%3E%3C/svg%3E';
|
||||
|
||||
const timestamp = document.createElement('div');
|
||||
timestamp.className = 'timeline-timestamp';
|
||||
timestamp.textContent = formatDate(image.fetched_at);
|
||||
|
||||
const tagsDiv = document.createElement('div');
|
||||
tagsDiv.className = 'timeline-tags';
|
||||
if (image.tags && image.tags.length > 0) {
|
||||
image.tags.forEach(tag => {
|
||||
const tagEl = document.createElement('span');
|
||||
tagEl.className = 'timeline-tag';
|
||||
if (selectedTag === tag) tagEl.classList.add('active');
|
||||
tagEl.textContent = tag;
|
||||
tagEl.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
tagSelect.value = tag;
|
||||
renderTimeline();
|
||||
};
|
||||
tagsDiv.appendChild(tagEl);
|
||||
});
|
||||
}
|
||||
|
||||
const size = document.createElement('div');
|
||||
size.className = 'timeline-size';
|
||||
size.textContent = formatSize(image.filesize);
|
||||
|
||||
content.appendChild(img);
|
||||
content.appendChild(timestamp);
|
||||
content.appendChild(tagsDiv);
|
||||
content.appendChild(size);
|
||||
|
||||
const marker = document.createElement('div');
|
||||
marker.className = 'timeline-marker';
|
||||
|
||||
item.appendChild(marker);
|
||||
item.appendChild(content);
|
||||
timeline.appendChild(item);
|
||||
});
|
||||
|
||||
timeline.style.display = 'block';
|
||||
empty.style.display = 'none';
|
||||
}
|
||||
|
||||
function showModal(image) {
|
||||
document.getElementById('modalImage').src = `${API_BASE}/api/images/${image.id}/download`;
|
||||
const info = document.getElementById('modalInfo');
|
||||
info.innerHTML = `
|
||||
<div style="margin-bottom: 12px;">
|
||||
<strong style="color: #667eea;">${formatDate(image.fetched_at)}</strong>
|
||||
</div>
|
||||
<div style="margin-bottom: 8px;">
|
||||
<strong>Size:</strong> ${formatSize(image.filesize)}
|
||||
</div>
|
||||
<div style="margin-bottom: 8px;">
|
||||
<strong>Hash:</strong> <code style="background: #f5f5f5; padding: 4px 8px; border-radius: 4px; font-size: 0.85em;">${image.file_hash.substring(0, 16)}...</code>
|
||||
</div>
|
||||
${image.tags && image.tags.length > 0 ? `
|
||||
<div>
|
||||
<strong>Tags:</strong> ${image.tags.map(tag => `<span class="timeline-tag">${tag}</span>`).join(' ')}
|
||||
</div>
|
||||
` : ''}
|
||||
`;
|
||||
modal.style.display = 'block';
|
||||
}
|
||||
|
||||
closeBtn.onclick = () => {
|
||||
modal.style.display = 'none';
|
||||
};
|
||||
|
||||
modal.onclick = (e) => {
|
||||
if (e.target === modal) {
|
||||
modal.style.display = 'none';
|
||||
}
|
||||
};
|
||||
|
||||
sortSelect.addEventListener('change', renderTimeline);
|
||||
tagSelect.addEventListener('change', renderTimeline);
|
||||
|
||||
autoRefresh.addEventListener('change', (e) => {
|
||||
if (e.target.checked) {
|
||||
loadImages();
|
||||
refreshInterval = setInterval(loadImages, 3000);
|
||||
} else {
|
||||
if (refreshInterval) clearInterval(refreshInterval);
|
||||
}
|
||||
});
|
||||
|
||||
// Initial load
|
||||
loadImages();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user