fix(gallery/filters): make feedback filters work globally when no guest_id is provided; remove guest_id from client photos query\n\n- Backend /api/gallery/:slug/photos: if filter present and guest_id missing, filter by like_count/favorite_count\n- Frontend useGalleryPhotos: stop passing random guestId (does not match server guest_identifier)\n\nThis makes Liked/Favorited filters reflect photos with aggregate feedback counts as expected.
This commit is contained in:
@@ -131,6 +131,17 @@ router.get('/:slug/photos', verifyGalleryAccess, async (req, res) => {
|
||||
|
||||
// Filter photos to only include those with feedback
|
||||
photos = photos.filter(photo => filteredPhotoIds.includes(photo.id));
|
||||
} else if (filter && !guest_id) {
|
||||
// Global filtering (by aggregate counts) when no guest identifier is provided
|
||||
// Normalize filter string
|
||||
const f = String(filter).toLowerCase();
|
||||
if (f === 'liked') {
|
||||
photos = photos.filter(p => (p.like_count || 0) > 0);
|
||||
} else if (f === 'favorited') {
|
||||
photos = photos.filter(p => (p.favorite_count || 0) > 0);
|
||||
} else if (f === 'liked,favorited' || f === 'favorited,liked') {
|
||||
photos = photos.filter(p => (p.like_count || 0) > 0 || (p.favorite_count || 0) > 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Then get comment counts separately
|
||||
|
||||
Reference in New Issue
Block a user