"use server";

/**
 * Public blog server actions: bumping view count.
 * Server action so the client component doesn't need a separate API route.
 */
import { prisma } from "@/lib/db";

export async function bumpBlogView(slug: string): Promise<void> {
  if (!slug || slug.length > 100) return;
  try {
    await prisma.blogPost.updateMany({
      where: { slug, publishedAt: { not: null } },
      data: { views: { increment: 1 } },
    });
  } catch {
    // Silent — view counter is best-effort.
  }
}
