Compare commits

...

7 Commits

Author SHA1 Message Date
Gitea Actions Bot 4bcca58a11 chore: bump version to 1.0.28
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2025-07-14 18:54:11 +00:00
paul 9fa5ba1cf7 fix: update GitHub mirror workflow to use orphan branch
Test and Lint / backend-test (push) Successful in 1m5s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m19s
Version and Release / version-bump (push) Successful in 35s
Version and Release / trigger-drone (push) Successful in 3s
2025-07-14 20:49:53 +02:00
paul 88919fa0d3 fix: critical boolean compatibility for PostgreSQL/SQLite
Fixed boolean value handling differences between databases:
- SQLite stores booleans as 0/1, PostgreSQL as true/false
- Add formatBoolean() calls to critical queries that were failing

Files fixed:
- adminEvents.js: Fixed status filters and archive queries
- adminDashboard.js: Fixed active/archived event counts
- expirationChecker.js: Fixed expiration checking queries
- dbCompat.js: Updated to avoid circular dependency

Added migration 024 to:
- Enable foreign keys for SQLite (PRAGMA foreign_keys = ON)
- Document boolean compatibility requirements

This fixes queries returning 0 results in SQLite when checking
boolean columns like is_active, is_archived. Critical for
proper event management and expiration handling.

Note: 23 more boolean comparisons remain to be fixed in other files.
2025-07-14 20:49:53 +02:00
Gitea Actions Bot 5e43fc9cd9 chore: bump version to 1.0.27
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-07-14 18:43:02 +00:00
paul f053f42b6d fix: comprehensive PostgreSQL/SQLite compatibility fixes
Mirror to GitHub / mirror (push) Successful in 19s
Test and Lint / backend-test (push) Successful in 1m8s
Test and Lint / frontend-test (push) Successful in 2m11s
Version and Release / version-bump (push) Successful in 34s
Version and Release / trigger-drone (push) Successful in 3s
continuous-integration/drone/push Build is passing
Critical fixes for database compatibility issues:

INSERT operations:
- Fix all INSERT queries to use .returning('id')
- Handle both PostgreSQL (returns objects) and SQLite (returns IDs)
- Fixed in: events.js, adminArchives.js, adminEvents-enhanced.js, create-test-event.js

Date operations:
- Replace SQLite-specific db.raw("datetime('now', '+30 days')")
- Use JavaScript Date objects for cross-database compatibility
- Fixed in: adminArchives.js

Database utilities:
- Add dbCompat.js utility for handling database differences
- Provides consistent API for inserts, dates, booleans, and DB-specific operations
- Centralized database compatibility logic

Migration:
- Add migration 023 documenting PostgreSQL compatibility requirements
- Ensures future developers are aware of compatibility needs

This resolves all 'not iterable' errors and ensures the application
works correctly with both PostgreSQL (production) and SQLite (development).
2025-07-14 20:38:37 +02:00
Gitea Actions Bot dc17e7d59d chore: bump version to 1.0.26
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2025-07-14 18:37:28 +00:00
paul f05ad87602 fix: PostgreSQL insert compatibility issues
Mirror to GitHub (Archive Method) / mirror (push) Failing after 17s
Mirror to GitHub (Rsync Method) / mirror (push) Failing after 17s
Mirror to GitHub / mirror (push) Failing after 19s
Test and Lint / backend-test (push) Successful in 1m7s
Test and Lint / frontend-test (push) Successful in 2m11s
continuous-integration/drone/push Build is passing
Version and Release / version-bump (push) Successful in 35s
Version and Release / trigger-drone (push) Successful in 3s
- Fix event creation failing with 'not iterable' error
- Add .returning('id') to insert queries for PostgreSQL
- Handle both PostgreSQL (returns objects) and SQLite (returns IDs)
- Add missing fields to email_queue insert

This fixes the 500 error when creating new events in production.
2025-07-14 20:32:21 +02:00
19 changed files with 243 additions and 183 deletions
@@ -1,39 +0,0 @@
name: Mirror to GitHub (Archive Method)
on:
push:
branches:
- main
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Mirror using git archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure git
git config --global user.name "Gitea Mirror Bot"
git config --global user.email "bot@noreply.gitea.local"
# Copy gitattributes
cp .gitattributes-github .gitattributes
# Create archive excluding files
git archive --format=tar HEAD | tar -x -C /tmp/export
# Initialize new repo in export directory
cd /tmp/export
git init
git add .
git commit -m "Mirror from Gitea: $(date '+%Y-%m-%d %H:%M:%S')"
# Push to GitHub
git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git
git push -f origin main
-42
View File
@@ -1,42 +0,0 @@
name: Mirror to GitHub (Rsync Method)
on:
push:
branches:
- main
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prepare mirror directory
run: |
# Create mirror directory
mkdir -p /tmp/github-mirror
# Use rsync to copy files, excluding sensitive ones
rsync -av --exclude-from='.github-mirror-exclude' ./ /tmp/github-mirror/
- name: Push to GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd /tmp/github-mirror
# Initialize git repo
git init
git config user.name "Gitea Mirror Bot"
git config user.email "bot@noreply.gitea.local"
# Add all files and commit
git add .
git commit -m "Mirror from Gitea: $(git --git-dir=$GITHUB_WORKSPACE/.git log -1 --format='%h %s')"
# Push to GitHub
git remote add origin https://x-access-token:${GITHUB_TOKEN}@github.com/YOUR_GITHUB_USERNAME/YOUR_REPO_NAME.git
git push -f origin main
+3 -2
View File
@@ -21,8 +21,9 @@ jobs:
- name: Create filtered branch
run: |
# Create a new branch for GitHub
git checkout -b github-mirror
git checkout --orphan -b github-mirror
# Remove sensitive files/directories
# Example: Remove .env files, private configs, etc.
@@ -49,7 +50,7 @@ jobs:
- name: Push to GitHub
env:
GITHUB_TOKEN: ${{ secrets.GITHUBTOKEN }}
GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
run: |
# Add GitHub remote
git remote add github https://x-access-token:${GITHUBTOKEN}@github.com/the-luap/picpeak.git
-66
View File
@@ -1,66 +0,0 @@
# Changelog
All notable changes to PicPeak will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Gitea workflows for selective GitHub mirroring
- Password visibility toggle on event creation form
- Translation for password requirement errors
### Changed
- Relaxed password requirements from 12 to 8 characters minimum
- Made special characters optional for gallery passwords
- Improved password strength requirements for better usability
### Fixed
- Production deployment issues with Traefik routing
- Database migration failures for email_queue table
- JSON parsing errors in production environment
- PostgreSQL compatibility issues
- Connection stability in production
## [1.0.22] - 2024-01-14
### Added
- Comprehensive error boundaries for better error handling
- Skeleton loading screens for improved perceived performance
- Offline indicator for network status
- Keyboard navigation support in gallery lightbox
- Skip links for accessibility
- Focus trap management for modals
### Changed
- Improved accessibility to WCAG 2.1 AA compliance
- Enhanced loading states with skeleton screens
- Better error recovery with component-level boundaries
### Fixed
- Missing translations in German locale
- Session timeout caching issues
- Email template JSON parsing errors
## [1.0.0] - 2024-01-01
### Added
- Initial release of PicPeak
- Photo gallery management system
- Automatic file watching and gallery creation
- Password-protected galleries
- Expiration system with email notifications
- Admin dashboard with analytics
- Multi-language support (EN, DE)
- Docker deployment support
- Email template customization
- User upload functionality
- Bulk download features
- Mobile-responsive design
- Theme customization options
[Unreleased]: https://github.com/the-luap/picpeak/compare/v1.0.22...HEAD
[1.0.22]: https://github.com/the-luap/picpeak/compare/v1.0.0...v1.0.22
[1.0.0]: https://github.com/the-luap/picpeak/releases/tag/v1.0.0
@@ -0,0 +1,22 @@
/**
* Ensure PostgreSQL compatibility for all insert operations
* This migration doesn't change the schema but ensures all tables
* are compatible with .returning() syntax
*/
exports.up = async function(knex) {
// This migration is informational only
// All insert operations should use .returning('id') going forward
console.log('PostgreSQL compatibility check:');
console.log('- All INSERT operations should use .returning("id")');
console.log('- All date operations should use ISO strings');
console.log('- Boolean values are handled automatically by Knex');
return Promise.resolve();
};
exports.down = async function(knex) {
// No rollback needed
return Promise.resolve();
};
@@ -0,0 +1,29 @@
/**
* Fix boolean compatibility issues between PostgreSQL and SQLite
* This migration updates the database configuration and existing data
*/
exports.up = async function(knex) {
const isPostgres = knex.client.config.client === 'pg';
if (!isPostgres) {
// Enable foreign keys for SQLite
await knex.raw('PRAGMA foreign_keys = ON');
// Note: SQLite stores booleans as 0/1
// No data migration needed as Knex handles this automatically
// But queries must use formatBoolean() helper
console.log('SQLite boolean compatibility check:');
console.log('- SQLite stores booleans as 0/1');
console.log('- All boolean comparisons should use formatBoolean() helper');
console.log('- Foreign keys enabled');
}
return Promise.resolve();
};
exports.down = async function(knex) {
// No rollback needed
return Promise.resolve();
};
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "picpeak-backend",
"version": "1.0.25",
"version": "1.0.28",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "picpeak-backend",
"version": "1.0.25",
"version": "1.0.28",
"dependencies": {
"adm-zip": "^0.5.16",
"archiver": "^5.3.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "picpeak-backend",
"version": "1.0.25",
"version": "1.0.28",
"description": "Backend for PicPeak event photo sharing platform",
"main": "server.js",
"scripts": {
+2 -1
View File
@@ -36,7 +36,8 @@ async function createTestEvent() {
await db('events').where('slug', eventData.slug).delete();
// Insert new event
const [eventId] = await db('events').insert(eventData);
const insertResult = await db('events').insert(eventData).returning('id');
const eventId = insertResult[0]?.id || insertResult[0];
console.log('Event created with ID:', eventId);
console.log('\nTest event created successfully!');
+8 -3
View File
@@ -211,12 +211,14 @@ router.post('/:id/restore', adminAuth, async (req, res) => {
categoriesMap.set(categoryName, existingCategory.id);
} else {
// Create the category if it doesn't exist
const [newCategoryId] = await db('photo_categories').insert({
const insertResult = await db('photo_categories').insert({
event_id: archive.id,
name: categoryName,
slug: categoryName.toLowerCase().replace(/[^a-z0-9]/g, '-'),
created_at: new Date()
});
}).returning('id');
const newCategoryId = insertResult[0]?.id || insertResult[0];
categoriesMap.set(categoryName, newCategoryId);
}
}
@@ -266,6 +268,9 @@ router.post('/:id/restore', adminAuth, async (req, res) => {
}
// Update event status
const thirtyDaysFromNow = new Date();
thirtyDaysFromNow.setDate(thirtyDaysFromNow.getDate() + 30);
await db('events')
.where('id', req.params.id)
.update({
@@ -273,7 +278,7 @@ router.post('/:id/restore', adminAuth, async (req, res) => {
is_active: true,
archive_path: null,
archived_at: null,
expires_at: db.raw("datetime('now', '+30 days')") // Reset expiration
expires_at: thirtyDaysFromNow.toISOString() // Reset expiration - works on both DBs
});
// Log activity
+4 -2
View File
@@ -77,12 +77,14 @@ router.post('/', adminAuth, [
}
// Create category
const [categoryId] = await db('photo_categories').insert({
const insertResult = await db('photo_categories').insert({
name,
slug: categorySlug,
is_global,
event_id: is_global ? null : event_id
});
}).returning('id');
const categoryId = insertResult[0]?.id || insertResult[0];
const category = await db('photo_categories').where('id', categoryId).first();
+6 -5
View File
@@ -2,6 +2,7 @@ const express = require('express');
const { db } = require('../database/db');
const { adminAuth } = require('../middleware/auth-enhanced-v2');
const { sanitizeDays, addDateRangeCondition } = require('../utils/sqlSecurity');
const { formatBoolean } = require('../utils/dbCompat');
const router = express.Router();
// Get dashboard statistics
@@ -9,8 +10,8 @@ router.get('/stats', adminAuth, async (req, res) => {
try {
// Get active events count
const activeEvents = await db('events')
.where('is_active', true)
.where('is_archived', false)
.where('is_active', formatBoolean(true))
.where('is_archived', formatBoolean(false))
.count('id as count')
.first();
@@ -20,8 +21,8 @@ router.get('/stats', adminAuth, async (req, res) => {
const now = new Date();
const expiringEvents = await db('events')
.where('is_active', true)
.where('is_archived', false)
.where('is_active', formatBoolean(true))
.where('is_archived', formatBoolean(false))
.where('expires_at', '<=', sevenDaysFromNow.toISOString())
.where('expires_at', '>', now.toISOString())
.count('id as count')
@@ -56,7 +57,7 @@ router.get('/stats', adminAuth, async (req, res) => {
// Get archived events count
const archivedEvents = await db('events')
.where('is_archived', true)
.where('is_archived', formatBoolean(true))
.count('id as count')
.first();
+5 -2
View File
@@ -83,7 +83,7 @@ router.post('/', adminAuth, [
await fs.mkdir(path.join(eventPath, 'individual'), { recursive: true });
// Insert into database
const [eventId] = await db('events').insert({
const insertResult = await db('events').insert({
slug,
event_type,
event_name,
@@ -99,7 +99,10 @@ router.post('/', adminAuth, [
created_at: new Date().toISOString(),
allow_user_uploads,
upload_category_id
});
}).returning('id');
// Handle both PostgreSQL (returns array of objects) and SQLite (returns array of IDs)
const eventId = insertResult[0]?.id || insertResult[0];
// Log activity
await logActivity('event_created',
+15 -9
View File
@@ -11,6 +11,7 @@ const { archiveEvent } = require('../services/archiveService');
const { escapeLikePattern } = require('../utils/sqlSecurity');
const { formatDate } = require('../utils/dateFormatter');
const { validatePasswordInContext, getBcryptRounds } = require('../utils/passwordValidation');
const { formatBoolean } = require('../utils/dbCompat');
// Create new event
router.post('/', adminAuth, [
@@ -92,7 +93,7 @@ router.post('/', adminAuth, [
await fs.mkdir(path.join(eventPath, 'individual'), { recursive: true });
// Insert into database
const [eventId] = await db('events').insert({
const insertResult = await db('events').insert({
slug,
event_type,
event_name,
@@ -108,7 +109,10 @@ router.post('/', adminAuth, [
created_at: new Date().toISOString(),
allow_user_uploads,
upload_category_id
});
}).returning('id');
// Handle both PostgreSQL (returns array of objects) and SQLite (returns array of IDs)
const eventId = insertResult[0]?.id || insertResult[0];
// Log activity
await logActivity('event_created',
@@ -133,7 +137,9 @@ router.post('/', adminAuth, [
gallery_password: password,
expiry_date: await formatDate(expires_at, emailLang),
welcome_message: welcome_message || ''
})
}),
status: 'pending',
created_at: new Date()
// scheduled_at will use default value
});
@@ -178,17 +184,17 @@ router.get('/', adminAuth, async (req, res) => {
// Apply status filter
if (status === 'active') {
query = query.where('is_active', true).where('is_archived', false);
query = query.where('is_active', formatBoolean(true)).where('is_archived', formatBoolean(false));
} else if (status === 'archived') {
query = query.where('is_archived', true);
query = query.where('is_archived', formatBoolean(true));
} else if (status === 'inactive') {
query = query.where('is_active', false).where('is_archived', false);
query = query.where('is_active', formatBoolean(false)).where('is_archived', formatBoolean(false));
} else if (status === 'expiring') {
const sevenDaysFromNow = new Date();
sevenDaysFromNow.setDate(sevenDaysFromNow.getDate() + 7);
query = query
.where('is_active', true)
.where('is_archived', false)
.where('is_active', formatBoolean(true))
.where('is_archived', formatBoolean(false))
.where('expires_at', '<=', sevenDaysFromNow.toISOString())
.where('expires_at', '>', new Date().toISOString());
}
@@ -549,7 +555,7 @@ router.post('/bulk-archive', adminAuth, [
// Get all events to archive
const events = await db('events')
.whereIn('id', eventIds)
.where('is_archived', false);
.where('is_archived', formatBoolean(false));
if (events.length === 0) {
return res.status(400).json({ error: 'No valid events found to archive' });
+5 -2
View File
@@ -64,7 +64,7 @@ router.post('/', adminAuth, [
await fs.mkdir(path.join(eventPath, 'individual'), { recursive: true });
// Insert into database
const [eventId] = await db('events').insert({
const insertResult = await db('events').insert({
slug,
event_type,
event_name,
@@ -76,7 +76,10 @@ router.post('/', adminAuth, [
color_theme,
share_link: shareLink,
expires_at
});
}).returning('id');
// Handle both PostgreSQL (returns array of objects) and SQLite (returns array of IDs)
const eventId = insertResult[0]?.id || insertResult[0];
// Queue creation email
const { queueEmail } = require('../services/emailProcessor');
+5 -4
View File
@@ -4,6 +4,7 @@ const { archiveEvent } = require('./archiveService');
const { queueEmail } = require('./emailProcessor');
const logger = require('../utils/logger');
const { formatDate } = require('../utils/dateFormatter');
const { formatBoolean } = require('../utils/dbCompat');
function startExpirationChecker() {
// Check every hour for expired events and warnings
@@ -21,8 +22,8 @@ async function checkExpirations() {
// Check for events needing warning emails
const eventsNeedingWarning = await db('events')
.where('is_active', true)
.where('is_archived', false)
.where('is_active', formatBoolean(true))
.where('is_archived', formatBoolean(false))
.where('expires_at', '<=', warningDate)
.where('expires_at', '>', now);
@@ -40,8 +41,8 @@ async function checkExpirations() {
// Check for expired events
const expiredEvents = await db('events')
.where('is_active', true)
.where('is_archived', false)
.where('is_active', formatBoolean(true))
.where('is_archived', formatBoolean(false))
.where('expires_at', '<=', now);
for (const event of expiredEvents) {
+133
View File
@@ -0,0 +1,133 @@
/**
* Database Compatibility Utilities
* Handles differences between PostgreSQL and SQLite
*/
// Note: Requiring db here creates circular dependency
// db should be passed as parameter or required where needed
/**
* Get database client type
* @returns {string} 'pg' or 'sqlite3'
*/
function getDbClient() {
return process.env.DATABASE_CLIENT || 'sqlite3';
}
/**
* Check if using PostgreSQL
* @returns {boolean}
*/
function isPostgreSQL() {
return getDbClient() === 'pg';
}
/**
* Handle insert operations that return IDs
* Works with both PostgreSQL and SQLite
* @param {object} query - Knex query builder
* @returns {Promise<number>} The inserted ID
*/
async function insertAndGetId(query) {
const result = await query.returning('id');
// PostgreSQL returns array of objects [{id: 1}]
// SQLite returns array of IDs [1]
return result[0]?.id || result[0];
}
/**
* Format date for database compatibility
* @param {Date} date - JavaScript Date object
* @returns {string} ISO string format that works on both databases
*/
function formatDateForDB(date) {
return date.toISOString();
}
/**
* Add days to a date (database agnostic)
* @param {Date} date - Starting date
* @param {number} days - Number of days to add
* @returns {Date} New date
*/
function addDays(date, days) {
const result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
/**
* Get date extraction SQL that works on both databases
* @param {object} db - Knex database instance
* @param {string} column - Column name
* @returns {object} Knex raw query
*/
function dateExtractSQL(db, column) {
if (isPostgreSQL()) {
return db.raw(`DATE(${column})`);
} else {
// SQLite uses date() function
return db.raw(`date(${column})`);
}
}
/**
* Get database size query
* @param {object} db - Knex database instance
* @param {string} dbName - Database name
* @returns {Promise<number>} Size in bytes
*/
async function getDatabaseSize(db, dbName) {
if (isPostgreSQL()) {
const result = await db.raw('SELECT pg_database_size(?) as size', [dbName]);
return result.rows[0]?.size || 0;
} else {
// For SQLite, check file size
const fs = require('fs').promises;
const path = require('path');
const dbPath = process.env.DATABASE_PATH || path.join(__dirname, '../../data/photo_sharing.db');
try {
const stats = await fs.stat(dbPath);
return stats.size;
} catch (error) {
console.error('Error getting SQLite database size:', error);
return 0;
}
}
}
/**
* Handle boolean values for database compatibility
* @param {boolean} value - Boolean value
* @returns {any} Database-appropriate boolean representation
*/
function formatBoolean(value) {
if (isPostgreSQL()) {
return value;
} else {
// SQLite stores booleans as 0/1
return value ? 1 : 0;
}
}
/**
* Parse boolean from database
* @param {any} value - Database boolean value
* @returns {boolean} JavaScript boolean
*/
function parseBoolean(value) {
return Boolean(value);
}
module.exports = {
getDbClient,
isPostgreSQL,
insertAndGetId,
formatDateForDB,
addDays,
dateExtractSQL,
getDatabaseSize,
formatBoolean,
parseBoolean
};
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "picpeak-frontend",
"version": "1.0.25",
"version": "1.0.28",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "picpeak-frontend",
"version": "1.0.25",
"version": "1.0.28",
"dependencies": {
"@tanstack/react-query": "^5.0.0",
"@tiptap/extension-link": "^2.25.0",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "picpeak-frontend",
"private": true,
"version": "1.0.25",
"version": "1.0.28",
"type": "module",
"scripts": {
"dev": "vite",