Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d05ff6380e | |||
| 605f773a7e | |||
| c844f634c8 | |||
| 1d94398e2d |
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.5.16",
|
"adm-zip": "^0.5.16",
|
||||||
"archiver": "^5.3.1",
|
"archiver": "^5.3.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-backend",
|
"name": "picpeak-backend",
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"description": "Backend for PicPeak event photo sharing platform",
|
"description": "Backend for PicPeak event photo sharing platform",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -61,4 +61,43 @@ On your production server:
|
|||||||
NODE_ENV=production node scripts/regenerate-thumbnails.js 2
|
NODE_ENV=production node scripts/regenerate-thumbnails.js 2
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: Replace `2` with the actual event ID from your database.
|
Note: Replace `2` with the actual event ID from your database.
|
||||||
|
|
||||||
|
## cleanup-thumbnails.js
|
||||||
|
|
||||||
|
Cleans up temporary and orphaned thumbnail files.
|
||||||
|
|
||||||
|
### Usage:
|
||||||
|
```bash
|
||||||
|
# Dry run - see what would be deleted
|
||||||
|
node scripts/cleanup-thumbnails.js --dry-run
|
||||||
|
|
||||||
|
# Actually delete orphaned thumbnails
|
||||||
|
node scripts/cleanup-thumbnails.js
|
||||||
|
```
|
||||||
|
|
||||||
|
### What it does:
|
||||||
|
- Identifies temporary thumbnails (thumb_temp_*)
|
||||||
|
- Finds orphaned thumbnails not linked to any photo
|
||||||
|
- Removes unnecessary files to free up space
|
||||||
|
- Reports statistics on cleanup
|
||||||
|
|
||||||
|
## diagnose-thumbnails.js
|
||||||
|
|
||||||
|
Diagnoses why thumbnails might not be showing for a specific event.
|
||||||
|
|
||||||
|
### Usage:
|
||||||
|
```bash
|
||||||
|
node scripts/diagnose-thumbnails.js 2
|
||||||
|
```
|
||||||
|
|
||||||
|
### What it checks:
|
||||||
|
- Thumbnail paths in database vs filesystem
|
||||||
|
- Path format inconsistencies
|
||||||
|
- Missing thumbnail files
|
||||||
|
- Provides SQL to fix path issues
|
||||||
|
|
||||||
|
### Common Issues:
|
||||||
|
1. **Path mismatch**: Database has wrong thumbnail path format
|
||||||
|
2. **Missing files**: Thumbnails were never generated
|
||||||
|
3. **Permission issues**: Web server can't read thumbnail files
|
||||||
Executable
+107
@@ -0,0 +1,107 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script to clean up orphaned and temporary thumbnails
|
||||||
|
* Usage: node scripts/cleanup-thumbnails.js [--dry-run]
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const { db } = require('../src/database/db');
|
||||||
|
|
||||||
|
const STORAGE_PATH = process.env.STORAGE_PATH || path.join(__dirname, '../../storage');
|
||||||
|
const THUMBNAILS_DIR = path.join(STORAGE_PATH, 'thumbnails');
|
||||||
|
|
||||||
|
async function cleanupThumbnails(dryRun = false) {
|
||||||
|
console.log('Starting thumbnail cleanup...');
|
||||||
|
console.log(`Thumbnails directory: ${THUMBNAILS_DIR}`);
|
||||||
|
console.log(`Mode: ${dryRun ? 'DRY RUN' : 'LIVE'}\n`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get all thumbnail files
|
||||||
|
const files = await fs.readdir(THUMBNAILS_DIR);
|
||||||
|
console.log(`Found ${files.length} files in thumbnails directory`);
|
||||||
|
|
||||||
|
// Get all valid thumbnail paths from database
|
||||||
|
const validThumbnails = await db('photos')
|
||||||
|
.whereNotNull('thumbnail_path')
|
||||||
|
.select('thumbnail_path');
|
||||||
|
|
||||||
|
const validPaths = new Set(
|
||||||
|
validThumbnails.map(t => path.basename(t.thumbnail_path))
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`Found ${validPaths.size} valid thumbnails in database\n`);
|
||||||
|
|
||||||
|
let tempCount = 0;
|
||||||
|
let orphanedCount = 0;
|
||||||
|
let validCount = 0;
|
||||||
|
let deletedCount = 0;
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
// Skip directories
|
||||||
|
const filePath = path.join(THUMBNAILS_DIR, file);
|
||||||
|
const stats = await fs.stat(filePath);
|
||||||
|
if (stats.isDirectory()) continue;
|
||||||
|
|
||||||
|
// Check if it's a temporary file
|
||||||
|
if (file.startsWith('thumb_temp_')) {
|
||||||
|
tempCount++;
|
||||||
|
console.log(`Temporary file: ${file}`);
|
||||||
|
|
||||||
|
if (!dryRun) {
|
||||||
|
try {
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
deletedCount++;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(` Failed to delete: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if it's an orphaned thumbnail
|
||||||
|
else if (!validPaths.has(file)) {
|
||||||
|
orphanedCount++;
|
||||||
|
console.log(`Orphaned file: ${file}`);
|
||||||
|
|
||||||
|
if (!dryRun) {
|
||||||
|
try {
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
deletedCount++;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(` Failed to delete: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
validCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n--- Summary ---');
|
||||||
|
console.log(`Total files: ${files.length}`);
|
||||||
|
console.log(`Valid thumbnails: ${validCount}`);
|
||||||
|
console.log(`Temporary files: ${tempCount}`);
|
||||||
|
console.log(`Orphaned files: ${orphanedCount}`);
|
||||||
|
if (!dryRun) {
|
||||||
|
console.log(`Deleted files: ${deletedCount}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Files to be deleted: ${tempCount + orphanedCount}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during cleanup:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse command line arguments
|
||||||
|
const dryRun = process.argv.includes('--dry-run');
|
||||||
|
|
||||||
|
// Run the cleanup
|
||||||
|
cleanupThumbnails(dryRun).then(async () => {
|
||||||
|
await db.destroy();
|
||||||
|
console.log('\nCleanup complete');
|
||||||
|
}).catch(async error => {
|
||||||
|
console.error('Cleanup failed:', error);
|
||||||
|
await db.destroy();
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
Executable
+132
@@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script to diagnose thumbnail serving issues
|
||||||
|
* Usage: node scripts/diagnose-thumbnails.js <eventId>
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const { db } = require('../src/database/db');
|
||||||
|
|
||||||
|
const STORAGE_PATH = process.env.STORAGE_PATH || path.join(__dirname, '../../storage');
|
||||||
|
const THUMBNAILS_DIR = path.join(STORAGE_PATH, 'thumbnails');
|
||||||
|
|
||||||
|
async function diagnoseThumbnails(eventId) {
|
||||||
|
if (!eventId) {
|
||||||
|
console.error('Usage: node scripts/diagnose-thumbnails.js <eventId>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Diagnosing thumbnails for event ID: ${eventId}`);
|
||||||
|
console.log(`Storage path: ${STORAGE_PATH}`);
|
||||||
|
console.log(`Thumbnails directory: ${THUMBNAILS_DIR}\n`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get event info
|
||||||
|
const event = await db('events').where('id', eventId).first();
|
||||||
|
if (!event) {
|
||||||
|
console.error(`Event not found with ID: ${eventId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Event: ${event.event_name} (${event.slug})`);
|
||||||
|
console.log(`Active: ${event.is_active}, Archived: ${event.is_archived}\n`);
|
||||||
|
|
||||||
|
// Get photos for this event
|
||||||
|
const photos = await db('photos')
|
||||||
|
.where('event_id', eventId)
|
||||||
|
.select('id', 'filename', 'path', 'thumbnail_path');
|
||||||
|
|
||||||
|
console.log(`Found ${photos.length} photos in database\n`);
|
||||||
|
|
||||||
|
let missingThumbnails = 0;
|
||||||
|
let existingThumbnails = 0;
|
||||||
|
let pathIssues = [];
|
||||||
|
|
||||||
|
for (const photo of photos.slice(0, 10)) { // Check first 10 photos
|
||||||
|
console.log(`Photo ID ${photo.id}: ${photo.filename}`);
|
||||||
|
console.log(` Photo path: ${photo.path}`);
|
||||||
|
console.log(` Thumbnail path in DB: ${photo.thumbnail_path}`);
|
||||||
|
|
||||||
|
if (photo.thumbnail_path) {
|
||||||
|
// Expected thumbnail filename
|
||||||
|
const expectedThumbName = `thumb_${photo.filename}`;
|
||||||
|
const expectedThumbPath = path.join(THUMBNAILS_DIR, expectedThumbName);
|
||||||
|
|
||||||
|
// Check if thumbnail exists
|
||||||
|
try {
|
||||||
|
await fs.access(expectedThumbPath);
|
||||||
|
console.log(` ✓ Thumbnail exists at: ${expectedThumbName}`);
|
||||||
|
existingThumbnails++;
|
||||||
|
|
||||||
|
// Check if DB path matches expected path
|
||||||
|
const dbThumbName = path.basename(photo.thumbnail_path);
|
||||||
|
if (dbThumbName !== expectedThumbName) {
|
||||||
|
console.log(` ⚠ Path mismatch! DB has: ${dbThumbName}, Expected: ${expectedThumbName}`);
|
||||||
|
pathIssues.push({
|
||||||
|
photoId: photo.id,
|
||||||
|
dbPath: photo.thumbnail_path,
|
||||||
|
expectedPath: `thumbnails/${expectedThumbName}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.log(` ✗ Thumbnail missing: ${expectedThumbName}`);
|
||||||
|
missingThumbnails++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(` ✗ No thumbnail path in database`);
|
||||||
|
missingThumbnails++;
|
||||||
|
}
|
||||||
|
console.log('');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('--- Summary ---');
|
||||||
|
console.log(`Existing thumbnails: ${existingThumbnails}`);
|
||||||
|
console.log(`Missing thumbnails: ${missingThumbnails}`);
|
||||||
|
console.log(`Path issues: ${pathIssues.length}`);
|
||||||
|
|
||||||
|
if (pathIssues.length > 0) {
|
||||||
|
console.log('\n--- Path Issues ---');
|
||||||
|
console.log('The following photos have incorrect thumbnail paths in the database:');
|
||||||
|
for (const issue of pathIssues) {
|
||||||
|
console.log(`Photo ID ${issue.photoId}:`);
|
||||||
|
console.log(` Current: ${issue.dbPath}`);
|
||||||
|
console.log(` Should be: ${issue.expectedPath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\nTo fix path issues, run:');
|
||||||
|
console.log(`UPDATE photos SET thumbnail_path = 'thumbnails/thumb_' || filename WHERE event_id = ${eventId};`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for any thumbnails in the directory that match this event
|
||||||
|
const files = await fs.readdir(THUMBNAILS_DIR);
|
||||||
|
const eventThumbnails = files.filter(f => {
|
||||||
|
// Try to match thumbnails for this event
|
||||||
|
for (const photo of photos) {
|
||||||
|
if (f === `thumb_${photo.filename}`) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`\n--- Filesystem Check ---`);
|
||||||
|
console.log(`Found ${eventThumbnails.length} thumbnails in directory for this event`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during diagnosis:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse command line arguments
|
||||||
|
const eventId = process.argv[2] ? parseInt(process.argv[2]) : null;
|
||||||
|
|
||||||
|
// Run the diagnosis
|
||||||
|
diagnoseThumbnails(eventId).then(async () => {
|
||||||
|
await db.destroy();
|
||||||
|
console.log('\nDiagnosis complete');
|
||||||
|
}).catch(async error => {
|
||||||
|
console.error('Diagnosis failed:', error);
|
||||||
|
await db.destroy();
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
Executable
+86
@@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script to test photo authentication
|
||||||
|
* Usage: node scripts/test-photo-auth.js <jwt-token>
|
||||||
|
*/
|
||||||
|
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
|
async function testPhotoAuth(token) {
|
||||||
|
if (!token) {
|
||||||
|
console.error('Usage: node scripts/test-photo-auth.js <jwt-token>');
|
||||||
|
console.error('\nTo get a token, login to a gallery and check localStorage for gallery_token_<slug>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseUrl = process.env.API_URL || 'http://localhost:3001';
|
||||||
|
|
||||||
|
console.log(`Testing photo authentication with token: ${token.substring(0, 20)}...`);
|
||||||
|
console.log(`Base URL: ${baseUrl}\n`);
|
||||||
|
|
||||||
|
// Test URLs
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
name: 'Thumbnail via static route',
|
||||||
|
url: `${baseUrl}/thumbnails/thumb_Test_Gallery_uncategorized_5210.jpg`,
|
||||||
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Photo via static route',
|
||||||
|
url: `${baseUrl}/photos/wedding-test-gallery-2025-07-14-1/Test_Gallery_uncategorized_5210.jpg`,
|
||||||
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Gallery photos API',
|
||||||
|
url: `${baseUrl}/api/gallery/wedding-test-gallery-2025-07-14-1/photos`,
|
||||||
|
headers: { 'Authorization': `Bearer ${token}` }
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const test of tests) {
|
||||||
|
console.log(`Testing: ${test.name}`);
|
||||||
|
console.log(`URL: ${test.url}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.get(test.url, {
|
||||||
|
headers: test.headers,
|
||||||
|
validateStatus: () => true // Don't throw on any status
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Status: ${response.status}`);
|
||||||
|
console.log(`Headers:`, response.headers['content-type']);
|
||||||
|
|
||||||
|
if (response.status === 200) {
|
||||||
|
if (test.name.includes('API')) {
|
||||||
|
console.log(`Photos count: ${response.data.photos?.length || 0}`);
|
||||||
|
} else {
|
||||||
|
console.log(`Content length: ${response.headers['content-length']} bytes`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`Error:`, response.data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Network error:`, error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('---\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode token to show info
|
||||||
|
try {
|
||||||
|
const parts = token.split('.');
|
||||||
|
const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString());
|
||||||
|
console.log('Token payload:', payload);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Failed to decode token');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get token from command line
|
||||||
|
const token = process.argv[2];
|
||||||
|
|
||||||
|
testPhotoAuth(token).catch(error => {
|
||||||
|
console.error('Test failed:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
@@ -363,12 +363,29 @@ router.delete('/:id', adminAuth, async (req, res) => {
|
|||||||
// Delete archive file if exists
|
// Delete archive file if exists
|
||||||
if (archive.archive_path) {
|
if (archive.archive_path) {
|
||||||
try {
|
try {
|
||||||
await fs.unlink(archive.archive_path);
|
const storagePath = process.env.STORAGE_PATH || path.join(__dirname, '../../../storage');
|
||||||
|
const fullArchivePath = path.join(storagePath, archive.archive_path);
|
||||||
|
await fs.unlink(fullArchivePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to delete archive file:', error);
|
console.error('Failed to delete archive file:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete thumbnails for this event
|
||||||
|
const photos = await db('photos').where('event_id', req.params.id).select('thumbnail_path');
|
||||||
|
const storagePath = process.env.STORAGE_PATH || path.join(__dirname, '../../../storage');
|
||||||
|
|
||||||
|
for (const photo of photos) {
|
||||||
|
if (photo.thumbnail_path) {
|
||||||
|
try {
|
||||||
|
const thumbPath = path.join(storagePath, photo.thumbnail_path.replace(/^\//, ''));
|
||||||
|
await fs.unlink(thumbPath);
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore errors - thumbnail might already be deleted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delete from database (cascade will delete photos and logs)
|
// Delete from database (cascade will delete photos and logs)
|
||||||
await db('events').where('id', req.params.id).delete();
|
await db('events').where('id', req.params.id).delete();
|
||||||
|
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ router.get('/:slug/photos', verifyGalleryAccess, async (req, res) => {
|
|||||||
photos: photos.map(photo => ({
|
photos: photos.map(photo => ({
|
||||||
id: photo.id,
|
id: photo.id,
|
||||||
filename: photo.filename,
|
filename: photo.filename,
|
||||||
url: `/photos/${photo.path}`,
|
url: `/api/gallery/${req.params.slug}/photo/${photo.id}`,
|
||||||
thumbnail_url: photo.thumbnail_path ? `/${photo.thumbnail_path}` : null,
|
thumbnail_url: photo.thumbnail_path ? `/api/gallery/${req.params.slug}/thumbnail/${photo.id}` : null,
|
||||||
type: photo.type,
|
type: photo.type,
|
||||||
category_id: photo.category_id,
|
category_id: photo.category_id,
|
||||||
category_name: photo.category_name,
|
category_name: photo.category_name,
|
||||||
@@ -320,6 +320,42 @@ router.get('/:slug/photo/:photoId', verifyGalleryAccess, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Serve thumbnail
|
||||||
|
router.get('/:slug/thumbnail/:photoId', verifyGalleryAccess, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { photoId } = req.params;
|
||||||
|
|
||||||
|
const photo = await db('photos')
|
||||||
|
.where({ id: photoId, event_id: req.event.id })
|
||||||
|
.first();
|
||||||
|
|
||||||
|
if (!photo || !photo.thumbnail_path) {
|
||||||
|
return res.status(404).json({ error: 'Thumbnail not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const thumbPath = path.join(getStoragePath(), photo.thumbnail_path);
|
||||||
|
|
||||||
|
// Check if file exists
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
try {
|
||||||
|
await fs.access(thumbPath);
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(404).json({ error: 'Thumbnail file not found' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set appropriate headers
|
||||||
|
res.setHeader('Content-Type', 'image/jpeg');
|
||||||
|
res.setHeader('Cache-Control', 'private, max-age=3600');
|
||||||
|
res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin');
|
||||||
|
|
||||||
|
// Send file
|
||||||
|
res.sendFile(path.resolve(thumbPath));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error serving thumbnail:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to serve thumbnail' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Get photo stats
|
// Get photo stats
|
||||||
router.get('/:slug/stats', verifyGalleryAccess, async (req, res) => {
|
router.get('/:slug/stats', verifyGalleryAccess, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Nginx Configuration Fix for Photo Authentication
|
||||||
|
|
||||||
|
If photos and thumbnails are not loading in gallery view but work in admin, it's likely that the Authorization header is being stripped by nginx or another reverse proxy.
|
||||||
|
|
||||||
|
## Common Issue
|
||||||
|
|
||||||
|
The `Authorization` header is often not passed through by default in nginx proxy configurations.
|
||||||
|
|
||||||
|
## Fix
|
||||||
|
|
||||||
|
Add these lines to your nginx configuration for the PicPeak location block:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3001;
|
||||||
|
|
||||||
|
# Important: Pass the Authorization header
|
||||||
|
proxy_pass_header Authorization;
|
||||||
|
proxy_set_header Authorization $http_authorization;
|
||||||
|
|
||||||
|
# Other standard proxy headers
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Alternative Fix Using Traefik
|
||||||
|
|
||||||
|
If using Traefik, ensure headers are passed:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
picpeak:
|
||||||
|
labels:
|
||||||
|
- "traefik.http.middlewares.picpeak-headers.headers.customrequestheaders.Authorization="
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
1. Check if Authorization header is reaching the backend:
|
||||||
|
```bash
|
||||||
|
curl -H "Authorization: Bearer YOUR_TOKEN" https://picpeak.yourdomain.com/thumbnails/test.jpg -v
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Check nginx logs to see if the header is present:
|
||||||
|
```bash
|
||||||
|
tail -f /var/log/nginx/access.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker Compose Fix
|
||||||
|
|
||||||
|
If using docker-compose with nginx proxy, add:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
environment:
|
||||||
|
- NGINX_PROXY_PASS_HEADER=Authorization
|
||||||
|
```
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-frontend",
|
"name": "picpeak-frontend",
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "picpeak-frontend",
|
"name": "picpeak-frontend",
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tanstack/react-query": "^5.0.0",
|
"@tanstack/react-query": "^5.0.0",
|
||||||
"@tiptap/extension-link": "^2.25.0",
|
"@tiptap/extension-link": "^2.25.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "picpeak-frontend",
|
"name": "picpeak-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.36",
|
"version": "1.0.38",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Reference in New Issue
Block a user