6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { db } from "@/app/db";
|
|
import { usersTable } from "@/app/db/schema";
|
|
|
|
// Define validation schema matching the database schema
|
|
const contactSchema = z.object({
|
|
name: z.string().min(1, "Name is required").max(255, "Name is too long"),
|
|
email: z.email("Invalid email address").max(255, "Email is too long"),
|
|
company: z.string().min(1, "Company is required").max(255, "Company name is too long"),
|
|
message: z.string().optional().prefault(""),
|
|
});
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
// Validate the request body
|
|
const validatedData = contactSchema.parse(body);
|
|
|
|
// Insert into database
|
|
const result = await db
|
|
.insert(usersTable)
|
|
.values({
|
|
name: validatedData.name,
|
|
email: validatedData.email,
|
|
company: validatedData.company,
|
|
message: validatedData.message,
|
|
})
|
|
.returning();
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
message: "Contact form submitted successfully",
|
|
data: result[0],
|
|
},
|
|
{ status: 201 }
|
|
);
|
|
} catch (error) {
|
|
if (error instanceof z.ZodError) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Validation error",
|
|
errors: error.issues,
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
console.error("Error submitting contact form:", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Failed to submit contact form",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|