feat: add preview_path migration and constants
Task 2: DB Migration - Add preview_path column to images table via ALTER TABLE - Migration runs automatically on database initialization - Handles duplicate column gracefully Task 3: Constants & Config - Export PREVIEW_FS_DIR constant (data/previews) - Export PREVIEW_CONFIG (800px, 85% quality, JPEG) - Update ImagePreviewService to import from constants - Update schema.sql documentation with preview_path
This commit is contained in:
parent
0471830e49
commit
940144cbf5
|
|
@ -12,9 +12,20 @@ const endpoints = {
|
|||
// Use path.join(__dirname, '..', UPLOAD_FS_DIR, fileName) in code
|
||||
const UPLOAD_FS_DIR = 'data/images';
|
||||
|
||||
// Filesystem directory (relative to backend/src) where preview images will be stored
|
||||
// Use path.join(__dirname, '..', PREVIEW_FS_DIR, fileName) in code
|
||||
const PREVIEW_FS_DIR = 'data/previews';
|
||||
|
||||
// Preview generation configuration
|
||||
const PREVIEW_CONFIG = {
|
||||
maxWidth: 800, // Maximum width in pixels
|
||||
quality: 85, // JPEG quality (0-100)
|
||||
format: 'jpeg' // Output format
|
||||
};
|
||||
|
||||
const time = {
|
||||
HOURS_24: 86400000,
|
||||
WEEK_1: 604800000
|
||||
};
|
||||
|
||||
module.exports = { endpoints, time, UPLOAD_FS_DIR };
|
||||
module.exports = { endpoints, time, UPLOAD_FS_DIR, PREVIEW_FS_DIR, PREVIEW_CONFIG };
|
||||
|
|
@ -90,6 +90,17 @@ class DatabaseManager {
|
|||
`);
|
||||
console.log('✓ Images Tabelle erstellt');
|
||||
|
||||
// Migration: Füge preview_path Feld zur images Tabelle hinzu (falls nicht vorhanden)
|
||||
try {
|
||||
await this.run('ALTER TABLE images ADD COLUMN preview_path TEXT');
|
||||
console.log('✓ preview_path Feld zur images Tabelle hinzugefügt');
|
||||
} catch (error) {
|
||||
// Feld existiert bereits - das ist okay
|
||||
if (!error.message.includes('duplicate column')) {
|
||||
console.warn('Migration Warnung:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Erstelle Indizes
|
||||
await this.run('CREATE INDEX IF NOT EXISTS idx_groups_group_id ON groups(group_id)');
|
||||
await this.run('CREATE INDEX IF NOT EXISTS idx_groups_year ON groups(year)');
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS images (
|
|||
upload_order INTEGER NOT NULL,
|
||||
file_size INTEGER,
|
||||
mime_type TEXT,
|
||||
preview_path TEXT, -- Path to preview/thumbnail image (added in migration 003)
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (group_id) REFERENCES groups(group_id) ON DELETE CASCADE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
const sharp = require('sharp');
|
||||
const path = require('path');
|
||||
const fs = require('fs').promises;
|
||||
|
||||
// Preview configuration
|
||||
const PREVIEW_CONFIG = {
|
||||
maxWidth: 800,
|
||||
quality: 85,
|
||||
format: 'jpeg'
|
||||
};
|
||||
|
||||
// Preview directory relative to backend/src
|
||||
const PREVIEW_FS_DIR = 'data/previews';
|
||||
const { PREVIEW_FS_DIR, PREVIEW_CONFIG, UPLOAD_FS_DIR } = require('../constants');
|
||||
|
||||
class ImagePreviewService {
|
||||
/**
|
||||
|
|
@ -121,7 +112,6 @@ class ImagePreviewService {
|
|||
* @returns {string} Absolute path to original file
|
||||
*/
|
||||
getOriginalPath(fileName) {
|
||||
const UPLOAD_FS_DIR = require('../constants').UPLOAD_FS_DIR;
|
||||
return path.join(__dirname, '..', UPLOAD_FS_DIR, fileName);
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +122,6 @@ class ImagePreviewService {
|
|||
async cleanupOrphanedPreviews() {
|
||||
try {
|
||||
const previewDir = path.join(__dirname, '..', PREVIEW_FS_DIR);
|
||||
const UPLOAD_FS_DIR = require('../constants').UPLOAD_FS_DIR;
|
||||
const originalDir = path.join(__dirname, '..', UPLOAD_FS_DIR);
|
||||
|
||||
// Check if preview directory exists
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user