fix: store uploaded logo as base64 in the database to support persistent storage and HTTPS domain routing in Next.js production builds
This commit is contained in:
@@ -74,6 +74,6 @@ model BookingSeat {
|
||||
model SystemSetting {
|
||||
id Int @id @default(autoincrement())
|
||||
key String @unique
|
||||
value String @db.Text
|
||||
value String @db.LongText
|
||||
}
|
||||
|
||||
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user