mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
3.6 KiB
3.6 KiB
Gallery Admin Page Fix
Problem
The gallery admin page was showing "Chyba při obnově galerie" (Error refreshing gallery) when clicking the "Obnovit z Zonerama" button. No albums were displayed even though data was visible on the frontpage.
Root Cause
- Missing Backend Endpoint: The admin page was calling
/api/v1/admin/gallery/refreshwhich didn't exist in the backend - Single Data Source: The admin page only loaded from
zonerama_profile.json, which hadalbums: null - Cache Data Issues: The Zonerama cache files contained empty/invalid data
Changes Made
Backend Changes
1. Added RefreshFromZonerama Method (internal/controllers/gallery_controller.go)
- New endpoint handler that:
- Loads the Zonerama URL from settings database
- Validates it's a Zonerama URL
- Triggers
services.RefreshZoneramaNow()in a goroutine (non-blocking) - Regenerates flat gallery files after successful fetch
- Returns immediate response to avoid timeout
2. Added Route (internal/routes/routes.go)
- Registered
POST /api/v1/admin/gallery/refreshendpoint - Maps to
galleryController.RefreshFromZonerama
Frontend Changes
3. Enhanced Admin Page Resilience (frontend/src/pages/admin/GalleryAdminPage.tsx)
- Modified
fetchAlbums()to load from both cache sources:zonerama_profile.json(primary source)zonerama_albums.json(fallback source)
- Filters out empty albums (albums without ID or title)
- Avoids duplicates when combining sources
- Matches the behavior of the frontpage
GallerySection.tsx
How It Works Now
-
Admin clicks "Obnovit z Zonerama":
- Frontend calls
POST /api/v1/admin/gallery/refresh - Backend loads Zonerama URL from settings
- Backend triggers async refresh in background
- Returns success immediately
- Frontend calls
-
Background Refresh Process:
- Fetches profile from Zonerama API (album metadata)
- Fetches each individual album with photos
- Saves to
zonerama_albums.json - Updates
zonerama_profile.json - Regenerates
gallery.jsonandzonerama_flat.json
-
Admin Page Loads Albums:
- Tries both
zonerama_profile.jsonandzonerama_albums.json - Combines and deduplicates results
- Filters out invalid/empty albums
- Displays combined album list
- Tries both
Testing
-
Build the backend:
go build -o bin/fotbal-club.exe✅ Compiles successfully
-
Run the server and test:
- Navigate to
/admin/galerie - Click "Obnovit z Zonerama"
- Should show success message
- Wait a few seconds and refresh page
- Albums should appear (if Zonerama API responds correctly)
- Navigate to
Configuration Required
Ensure the Zonerama URL is configured in Settings:
- Go to Admin → Settings
- Set "Gallery URL" to your Zonerama profile URL
- Example:
https://eu.zonerama.com/FKKofolaKrnov/1470757
- Example:
- The URL must contain "zonerama.com"
Known Issues
The current cache files (zonerama_profile.json and zonerama_albums.json) contain empty data, which suggests:
- The Zonerama external API might be experiencing issues
- The URL format might have changed
- Network connectivity issues
The "Refresh" button will trigger a fresh fetch from the Zonerama API, which should resolve this if the API is working correctly.
Related Files
internal/controllers/gallery_controller.go- Gallery endpointsinternal/routes/routes.go- Route registrationinternal/services/prefetch_service.go- Zonerama fetch logicfrontend/src/pages/admin/GalleryAdminPage.tsx- Admin UIfrontend/src/components/home/GallerySection.tsx- Frontend display