// Image management functionality let currentPage = 1; let totalPages = 1; let imageBlobCache = new Map(); // Cache for blob URLs // Load image with authentication and return blob URL async function loadImageBlob(imageId) { // Check cache first if (imageBlobCache.has(imageId)) { return imageBlobCache.get(imageId); } try { const blobUrl = await apiClient.downloadImageBlob(imageId); imageBlobCache.set(imageId, blobUrl); return blobUrl; } catch (error) { console.error(`Failed to load image ${imageId}:`, error); throw error; // Let the caller handle the error } } // Clean up blob URLs to prevent memory leaks function cleanupBlobCache() { for (const [imageId, blobUrl] of imageBlobCache.entries()) { if (blobUrl.startsWith('blob:')) { URL.revokeObjectURL(blobUrl); } } imageBlobCache.clear(); } // Load images with pagination async function loadImages(page = 1, tags = null) { if (!config.isConfigured()) { showAlert('Please configure your API settings first.', 'warning'); return; } const container = document.getElementById('imagesContainer'); container.innerHTML = '
Upload your first image to get started!
${formatDate(image.upload_date)}
${image.tags && image.tags.length > 0 ? `${escapeHtml(image.description || 'No description')}
Created: ${formatDate(image.upload_date)}
Size: ${formatFileSize(image.file_size)}
Type: ${image.content_type}