Add OG image support for WhatsApp/social media link previews

This commit is contained in:
2026-01-06 02:03:51 +01:00
parent 50a3c7fe24
commit a7b2169ec8
4 changed files with 94 additions and 12 deletions

View File

@@ -34,6 +34,7 @@ export interface Questionnaire {
slug: string;
title: string;
description: string | null;
og_image: string | null;
is_private: boolean;
created_by: number;
created_at: string;
@@ -121,6 +122,13 @@ export function initializeDatabase(): void {
// Column already exists, ignore
}
// Migration: Add og_image column if it doesn't exist
try {
db.exec(`ALTER TABLE questionnaires ADD COLUMN og_image TEXT`);
} catch (e) {
// Column already exists, ignore
}
// Participants table
db.exec(`
CREATE TABLE IF NOT EXISTS participants (
@@ -251,10 +259,10 @@ export const userOps = {
// Questionnaire operations
export const questionnaireOps = {
create: (uuid: string, slug: string, title: string, description: string | null, isPrivate: boolean, createdBy: number): number => {
create: (uuid: string, slug: string, title: string, description: string | null, ogImage: string | null, isPrivate: boolean, createdBy: number): number => {
const result = db.prepare(
'INSERT INTO questionnaires (uuid, slug, title, description, is_private, created_by) VALUES (?, ?, ?, ?, ?, ?)'
).run(uuid, slug, title, description, isPrivate ? 1 : 0, createdBy);
'INSERT INTO questionnaires (uuid, slug, title, description, og_image, is_private, created_by) VALUES (?, ?, ?, ?, ?, ?, ?)'
).run(uuid, slug, title, description, ogImage, isPrivate ? 1 : 0, createdBy);
return result.lastInsertRowid as number;
},
@@ -280,8 +288,8 @@ export const questionnaireOps = {
`).all() as Questionnaire[];
},
update: (id: number, slug: string, title: string, description: string | null, isPrivate: boolean): void => {
db.prepare('UPDATE questionnaires SET slug = ?, title = ?, description = ?, is_private = ? WHERE id = ?').run(slug, title, description, isPrivate ? 1 : 0, id);
update: (id: number, slug: string, title: string, description: string | null, ogImage: string | null, isPrivate: boolean): void => {
db.prepare('UPDATE questionnaires SET slug = ?, title = ?, description = ?, og_image = ?, is_private = ? WHERE id = ?').run(slug, title, description, ogImage, isPrivate ? 1 : 0, id);
},
delete: (id: number): void => {