54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { and, eq } from "drizzle-orm";
|
|
import { z } from "zod";
|
|
import { auth } from "@/app/(auth)/auth";
|
|
import { db } from "@/lib/db";
|
|
import { canvasProject } from "@/lib/db/schema";
|
|
|
|
const canvasIdSchema = z.string().uuid();
|
|
|
|
export async function GET(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
const session = await auth();
|
|
if (!session?.user?.id) {
|
|
return Response.json(
|
|
{ success: false, error: "未登录" },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const { id: rawId } = await params;
|
|
const parsedId = canvasIdSchema.safeParse(rawId);
|
|
if (!parsedId.success) {
|
|
return Response.json(
|
|
{ success: false, error: "画布 ID 无效" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const id = parsedId.data;
|
|
const [project] = await db
|
|
.select({ updatedAt: canvasProject.updatedAt })
|
|
.from(canvasProject)
|
|
.where(
|
|
and(
|
|
eq(canvasProject.id, id),
|
|
eq(canvasProject.userId, session.user.id)
|
|
)
|
|
)
|
|
.limit(1);
|
|
|
|
if (!project) {
|
|
return Response.json(
|
|
{ success: false, error: "画布不存在" },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
return Response.json(
|
|
{ success: true, data: { updatedAt: project.updatedAt.toISOString() } },
|
|
{ headers: { "Cache-Control": "no-store" } }
|
|
);
|
|
}
|