From 6ea6a5853203aec0ec71fcd316ea69e59449e343 Mon Sep 17 00:00:00 2001 From: Kenzo Date: Tue, 9 Dec 2025 18:10:25 +0100 Subject: [PATCH] feat: Add vips dependencies for sharp in backend Dockerfile - Added `vips-dev` and `vips` to build and runtime dependencies. - Updated installation process to ensure compilation --- backend/src/routes/events.ts | 6 ++++-- backend/src/routes/gallery.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/src/routes/events.ts b/backend/src/routes/events.ts index 997a21e..4db201a 100644 --- a/backend/src/routes/events.ts +++ b/backend/src/routes/events.ts @@ -4,7 +4,6 @@ import { events } from '../db/schema.js'; import { eq } from 'drizzle-orm'; import fs from 'fs'; import path from 'path'; -import sharp from 'sharp'; // Fastify JSON schema for event body const eventBodyJsonSchema = { @@ -114,12 +113,15 @@ const eventsRoute: FastifyPluginAsync = async (fastify) => { let outBuffer: Buffer | null = null; let outExt = '.webp'; try { + // Lazy load sharp only when needed + const sharp = (await import('sharp')).default; outBuffer = await sharp(inputBuffer) .rotate() .resize({ width: 1600, withoutEnlargement: true }) .webp({ quality: 82 }) .toBuffer(); - } catch { + } catch (err) { + fastify.log.warn({ err }, 'Sharp processing failed, using original image'); outBuffer = inputBuffer; // naive extension from mimetype const extFromMime = mime.split('/')[1] || 'bin'; diff --git a/backend/src/routes/gallery.ts b/backend/src/routes/gallery.ts index 966ea3d..4279c84 100644 --- a/backend/src/routes/gallery.ts +++ b/backend/src/routes/gallery.ts @@ -5,7 +5,6 @@ import { galleryImages } from '../db/schema.js'; import { eq } from 'drizzle-orm'; import fs from 'fs'; import path from 'path'; -import sharp from 'sharp'; // Fastify JSON schema for gallery image body const galleryBodyJsonSchema = { @@ -106,12 +105,15 @@ const galleryRoute: FastifyPluginAsync = async (fastify) => { let outBuffer: Buffer | null = null; let outExt = '.webp'; try { + // Lazy load sharp only when needed + const sharp = (await import('sharp')).default; outBuffer = await sharp(inputBuffer) .rotate() .resize({ width: 1600, withoutEnlargement: true }) .webp({ quality: 82 }) .toBuffer(); - } catch { + } catch (err) { + fastify.log.warn({ err }, 'Sharp processing failed, using original image'); outBuffer = inputBuffer; // naive extension from mimetype const extFromMime = mime.split('/')[1] || 'bin';