mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
6.8 KiB
6.8 KiB
Zonerama Gallery Fix - Implementation Summary
Problem Description
The Zonerama gallery was not displaying any photos on the admin page or frontend, despite having profile data in zonerama_profile.json.
Root Cause
- Profile fetch (
zonerama_profile.json) only contained album metadata without photos (fetched withphoto_limit=0) - Album storage (
zonerama_albums.json) didn't exist - individual albums with photos were never fetched - Flat files (
zonerama_flat.jsonandgallery.json) were empty because there were no albums with photos to flatten - Frontend reads from
zonerama_flat.json→ displays nothing
Solution Implemented
Backend Changes (internal/services/prefetch_service.go)
Modified fetchZonerama() function:
- Fetch profile with album metadata (as before)
- NEW: Fetch each album individually with photos using the Zonerama API
- NEW: Store albums in
zonerama_albums.jsonwith all photo data - NEW: Regenerate flat files for frontend consumption
Added fetchZoneramaAlbums() helper function:
- Fetches individual albums from the profile
- Calls the Zonerama API
/zonerama-albumendpoint for each album - Configurable photo limit per album (default: 50, env:
ZONERAMA_PHOTO_LIMIT) - Includes retry logic and delays between requests to avoid overwhelming the API
Frontend Changes (frontend/src/components/home/PhotosSection.tsx)
Updated the photo manifest loading to use fallback paths:
- Primary:
/cache/prefetch/zonerama_flat.json(new unified location) - Fallback 1:
/cache/prefetch/zonerama/manifest.json(legacy path) - Fallback 2:
/cache/prefetch/gallery.json(alternative)
Data Flow
1. fetchZonerama() is called (profile URL)
↓
2. Fetch profile → save to zonerama_profile.json (album metadata only)
↓
3. Parse albums from profile
↓
4. For each album:
- Fetch album with photos from API
- Collect album data with photos
↓
5. Save all albums → zonerama_albums.json
↓
6. RegenerateFlatGalleryFiles()
- Read zonerama_albums.json
- Flatten all photos from all albums
- Write to zonerama_flat.json and gallery.json
↓
7. Frontend reads zonerama_flat.json → displays photos
Configuration
Environment Variables
ZONERAMA_ALBUM_LIMIT: Max number of albums to fetch from profile (default: 10)ZONERAMA_PHOTO_LIMIT: Max photos per album (default: 50)ZONERAMA_FETCH_INTERVAL_MINUTES: How often to refresh (default: 1440 = daily)ENABLE_ZONERAMA_PREFETCH: Enable/disable Zonerama fetching (default: true)
How to Trigger Album Fetch
Automatic (Recommended)
The system will automatically fetch albums:
- On startup (after 15 seconds)
- Daily (configurable interval)
Manual Trigger
Option 1: Admin Panel
- Go to Admin → Settings → Sociální sítě
- Ensure Zonerama URL is configured
- Go to Admin → Galerie (or trigger via prefetch)
- Click "Spustit stažení" button
Option 2: API Call
POST /api/v1/admin/prefetch/trigger
Authorization: Bearer <admin-token>
Option 3: Direct Service Call (for testing)
# Trigger Zonerama refresh directly
curl "http://localhost:8080/api/v1/admin/prefetch/trigger" \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN"
Files Generated
After successful fetch, you should have:
-
cache/prefetch/zonerama_profile.json- Profile metadata with album list (no photos inside albums)
- Source of truth for which albums exist
-
cache/prefetch/zonerama_albums.json← NEW- Array of albums, each with full photo data
- This is the main storage for album+photo data
-
cache/prefetch/zonerama_flat.json← NEW (regenerated)- Flattened list of all photos from all albums
- Used by admin page and frontend
-
cache/prefetch/gallery.json← NEW (regenerated)- Same content as zonerama_flat.json (for compatibility)
-
cache/prefetch/zonerama_flat.json.hdr← NEW- Metadata (fetched_at, source link)
Verification
Check if albums were fetched:
# Should show albums with photos
cat cache/prefetch/zonerama_albums.json | jq '.[0].photos | length'
# Should show flattened photos
cat cache/prefetch/zonerama_flat.json | jq 'length'
Check admin page:
- Go to
/admin/zonerama - Should display photo count and photos in grid
- "Počet fotek" should be > 0
Check frontend:
- Go to homepage
- "Fotogalerie" section should show 6 photos
Troubleshooting
No photos showing after fetch
-
Check Zonerama URL is configured:
cat cache/prefetch/settings.json | jq '.zonerama_url' -
Check profile was fetched:
cat cache/prefetch/zonerama_profile.json | jq '.albums | length' -
Check albums were fetched:
ls -lh cache/prefetch/zonerama_albums.json cat cache/prefetch/zonerama_albums.json | jq 'length' -
Check flat files were generated:
cat cache/prefetch/zonerama_flat.json | jq 'length' -
Check logs for errors:
# Look for "[prefetch] Zonerama" messages grep "Zonerama" logs/app.log
API Rate Limiting
The implementation includes:
- 500ms delay between album fetches
- Exponential backoff on profile fetch (3 retries)
- Configurable limits via environment variables
If you hit rate limits, you can:
- Reduce
ZONERAMA_ALBUM_LIMIT(fetch fewer albums) - Reduce
ZONERAMA_PHOTO_LIMIT(fewer photos per album) - Increase
ZONERAMA_FETCH_INTERVAL_MINUTES(fetch less frequently)
API Endpoints
Public
GET /api/v1/gallery/albums- Get all albumsGET /api/v1/gallery/albums/:id- Get single album with photos
Admin
GET /api/v1/admin/gallery/profile- Get Zonerama profile metadataPOST /api/v1/admin/gallery/albums/fetch- Fetch single album by URLDELETE /api/v1/admin/gallery/albums/:id- Delete album from collectionPOST /api/v1/admin/prefetch/trigger- Trigger full prefetch (includes Zonerama)
Admin Features
Fetch Individual Albums
Admins can manually add albums:
POST /api/v1/admin/gallery/albums/fetch
{
"link": "https://eu.zonerama.com/FKKofolaKrnov/Album/13939668",
"photo_limit": 50
}
This allows:
- Adding new albums not in the profile
- Re-fetching specific albums with updated photos
- Fetching with custom photo limits
Album Management
- View all fetched albums:
GET /api/v1/gallery/albums - Delete unwanted albums:
DELETE /api/v1/admin/gallery/albums/:id - Albums are automatically included in flat files after add/delete
Notes
- Albums are fetched with photos inline (not downloaded to disk)
- Photos are served via proxy to avoid CORS issues
- The system maintains both profile metadata and full album data
- Flat files are regenerated automatically after any album operation
- Frontend has fallback logic for backward compatibility