From 433e6dfc6c5b300edde57f5c7504e25e6db946b4 Mon Sep 17 00:00:00 2001 From: Rio Date: Thu, 18 Jun 2026 14:52:52 +0700 Subject: [PATCH] fix: store uploaded logo as base64 in the database to support persistent storage and HTTPS domain routing in Next.js production builds --- prisma/schema.prisma | 2 +- src/app/api/admin/settings/route.ts | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 7eaf88b..32da4bb 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -74,6 +74,6 @@ model BookingSeat { model SystemSetting { id Int @id @default(autoincrement()) key String @unique - value String @db.Text + value String @db.LongText } diff --git a/src/app/api/admin/settings/route.ts b/src/app/api/admin/settings/route.ts index e79972a..7d34c9d 100644 --- a/src/app/api/admin/settings/route.ts +++ b/src/app/api/admin/settings/route.ts @@ -3,9 +3,6 @@ import { prisma } from '@/lib/db'; import { requireAdmin } from '@/lib/auth'; import { getSettings } from '@/lib/settings'; -import { promises as fs } from 'fs'; -import path from 'path'; - export async function GET() { try { await requireAdmin(); @@ -61,22 +58,15 @@ export async function PUT(request: Request) { }); } - // Handle logo file upload + // Handle logo file upload (Convert to base64 Data URL to support Docker persistence and HTTPS domains) const logoFile = formData.get('logoFile') as File | null; if (logoFile && logoFile.size > 0) { const bytes = await logoFile.arrayBuffer(); const buffer = Buffer.from(bytes); - - const uploadDir = path.join(process.cwd(), 'public', 'uploads'); - // Create folder recursively if it doesn't exist - await fs.mkdir(uploadDir, { recursive: true }); - - const filename = `logo-${Date.now()}${path.extname(logoFile.name)}`; - const filePath = path.join(uploadDir, filename); - - await fs.writeFile(filePath, buffer); - - const logoUrl = `/uploads/${filename}`; + const base64Image = buffer.toString('base64'); + const mimeType = logoFile.type || 'image/png'; + const logoUrl = `data:${mimeType};base64,${base64Image}`; + await prisma.systemSetting.upsert({ where: { key: 'logoImageUrl' }, update: { value: logoUrl },