diff --git a/src/app/api/webhook/projects/route.ts b/src/app/api/webhook/projects/route.ts index edaf6f3..1704546 100644 --- a/src/app/api/webhook/projects/route.ts +++ b/src/app/api/webhook/projects/route.ts @@ -4,9 +4,9 @@ import type { ProjectStatus, LinkType } from '@prisma/client' import { isValidApiKey } from '@/lib/auth' import { WebhookPayloadSchema, - ProjectInputSchema, + ProjectIngestionInputSchema, type WebhookPayload, - type ProjectInput, + type ProjectIngestionInput, } from '@/lib/validations' import { findExistingProject, @@ -67,7 +67,7 @@ export async function POST(request: NextRequest) { const projectData = payload.projects[i] // Validate individual project - const projectValidation = ProjectInputSchema.safeParse(projectData) + const projectValidation = ProjectIngestionInputSchema.safeParse(projectData) if (!projectValidation.success) { results.failed++ @@ -82,7 +82,7 @@ export async function POST(request: NextRequest) { } try { - const validProject = projectValidation.data as ProjectInput + const validProject = projectValidation.data as ProjectIngestionInput // 多级去重:查找已存在的项目 const existingProject = await findExistingProject(validProject) diff --git a/src/lib/validations.ts b/src/lib/validations.ts index eb6e90e..27ecb4c 100644 --- a/src/lib/validations.ts +++ b/src/lib/validations.ts @@ -53,6 +53,11 @@ export const ProjectInputSchema = ProjectBaseSchema.extend({ links: z.array(ExternalLinkSchema).min(1, "At least one link is required").max(10), }); +export const ProjectIngestionInputSchema = ProjectBaseSchema.extend({ + tags: z.array(TagSchema).min(1, "At least one tag is required"), + links: z.array(ExternalLinkSchema).min(1, "At least one link is required").max(10), +}); + // ================================ // Webhook Schemas // ================================ @@ -62,7 +67,7 @@ export const WebhookAuthSchema = z.object({ }); export const WebhookPayloadSchema = WebhookAuthSchema.extend({ - projects: z.array(ProjectInputSchema).min(1).max(100), + projects: z.array(ProjectIngestionInputSchema).min(1).max(100), }); // ================================ @@ -299,6 +304,7 @@ export const N8NChatJobResponseSchema = z.object({ export type ExternalLink = z.infer; export type Tag = z.infer; export type ProjectInput = z.infer; +export type ProjectIngestionInput = z.infer; export type WebhookPayload = z.infer; export type ProjectQuery = z.infer; export type TaskStatus = z.infer;