Fix issue #22: Gallery filter counts disappearing and upload errors
This commit comprehensively addresses the persistent issues reported in #22: 1. Gallery Filter Bug - Counts Disappearing - Root cause: Frontend fetched filtered photos from backend, then calculated counts from already-filtered data - Fix: Always fetch ALL photos, apply filtering client-side only - Benefits: Counts always accurate, filters work correctly in combo - Changed: frontend/src/components/gallery/GalleryView.tsx:76 2. Upload ENOENT Errors - Root cause: /tmp/uploads/ directory assumed to exist - Fix: Verify and create temp directory before multer initialization - Changed: backend/src/routes/gallery.js:814-825 3. Upload "Not Iterable" Errors - Root cause: normalizeFiles() didn't handle null/edge cases - Fix: Enhanced error handling with try-catch and graceful degradation - Changed: backend/src/services/photoProcessor.js:10-52 4. Enhanced Upload Debugging - Added file existence verification before copy operations - Improved temp file cleanup (properly handle ENOENT) - Comprehensive error logging with full context - Changed: backend/src/services/photoProcessor.js:108-233 Technical Details: - Gallery filtering now entirely client-side (simpler architecture) - Upload error messages now include full diagnostic context - Temp file cleanup handles ENOENT gracefully (expected scenario) - All fixes preserve backward compatibility Testing: - Gallery filters: Verify counts stay visible when filtering - Uploads: Test single/batch uploads, check temp cleanup - Logs: Verify detailed error context on failures See ISSUE_22_FIX_SUMMARY.md for complete analysis and testing guide. Fixes #22
This commit is contained in:
@@ -800,22 +800,35 @@ router.get('/:slug/stats', verifyGalleryAccess, async (req, res) => {
|
||||
router.post('/:eventId/upload', verifyGalleryAccess, async (req, res) => {
|
||||
try {
|
||||
const eventId = parseInt(req.params.eventId);
|
||||
|
||||
|
||||
// Verify the event matches the token
|
||||
if (req.event.id !== eventId) {
|
||||
return res.status(403).json({ error: 'Access denied' });
|
||||
}
|
||||
|
||||
|
||||
// Check if user uploads are allowed
|
||||
if (!req.event.allow_user_uploads) {
|
||||
return res.status(403).json({ error: 'User uploads are not allowed for this event' });
|
||||
}
|
||||
|
||||
|
||||
// Ensure temp upload directory exists
|
||||
const fs = require('fs');
|
||||
const tempUploadDir = '/tmp/uploads/';
|
||||
if (!fs.existsSync(tempUploadDir)) {
|
||||
try {
|
||||
fs.mkdirSync(tempUploadDir, { recursive: true, mode: 0o755 });
|
||||
logger.info('Created temp upload directory:', tempUploadDir);
|
||||
} catch (mkdirErr) {
|
||||
logger.error('Failed to create temp upload directory:', mkdirErr);
|
||||
return res.status(500).json({ error: 'Server configuration error: unable to create upload directory' });
|
||||
}
|
||||
}
|
||||
|
||||
// Import multer and photo processing
|
||||
const multer = require('multer');
|
||||
const upload = multer({
|
||||
dest: '/tmp/uploads/',
|
||||
limits: {
|
||||
const upload = multer({
|
||||
dest: tempUploadDir,
|
||||
limits: {
|
||||
fileSize: 50 * 1024 * 1024, // 50MB
|
||||
files: 10 // Max 10 files at once
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user