feat: add admin dashboard and core API routes with Docker configuration
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { ContentStatus } from "@prisma/client";
|
||||
import { getAuthUser } from "@/lib/auth-utils";
|
||||
import { sanitizeHTML } from "@/lib/sanitize";
|
||||
import { safeUrl } from "@/lib/utils";
|
||||
|
||||
export async function createEvent(data: {
|
||||
title: string;
|
||||
@@ -14,20 +17,33 @@ export async function createEvent(data: {
|
||||
tags?: string[];
|
||||
}) {
|
||||
try {
|
||||
const authUser = await getAuthUser();
|
||||
if (!authUser) {
|
||||
return { success: false, error: "Authentification requise" };
|
||||
}
|
||||
|
||||
const slug = data.title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/(^-|-$)/g, '');
|
||||
|
||||
let validatedLink: string | null = null;
|
||||
if (data.link && data.link.trim()) {
|
||||
const checked = safeUrl(data.link.trim());
|
||||
if (checked !== '#') {
|
||||
validatedLink = checked;
|
||||
}
|
||||
}
|
||||
|
||||
const event = await prisma.event.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
title: data.title.trim().slice(0, 200),
|
||||
description: sanitizeHTML(data.description || ''),
|
||||
date: new Date(data.date),
|
||||
location: data.location,
|
||||
location: data.location.trim().slice(0, 200),
|
||||
thumbnailUrl: data.thumbnailUrl,
|
||||
link: data.link || null,
|
||||
tags: data.tags || [],
|
||||
link: validatedLink,
|
||||
tags: Array.isArray(data.tags) ? data.tags.slice(0, 20) : [],
|
||||
status: 'PENDING' as ContentStatus, // Always pending for user submission
|
||||
slug: `${slug}-${Math.random().toString(36).substring(2, 7)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user