feat: add admin accounts and image templates
This commit is contained in:
35
app/api/image-templates/[id]/route.ts
Normal file
35
app/api/image-templates/[id]/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { deleteImageTemplate, updateImageTemplate } from "@/lib/server/data-store";
|
||||
import { jsonError, jsonOk, readJsonBody } from "@/lib/server/api";
|
||||
import { requireAppUser } from "@/lib/server/auth/current-user";
|
||||
import { normalizeImageTemplateUpdate } from "@/lib/server/image-template-input";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{ id: string }>;
|
||||
};
|
||||
|
||||
export async function PATCH(request: Request, context: RouteContext) {
|
||||
try {
|
||||
const user = await requireAppUser();
|
||||
const { id } = await context.params;
|
||||
const body = await readJsonBody(request);
|
||||
const template = await updateImageTemplate(id, user.id, normalizeImageTemplateUpdate(body));
|
||||
if (!template) return jsonError(new Error("模板不存在"), 404);
|
||||
return jsonOk({ template });
|
||||
} catch (error) {
|
||||
return jsonError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: Request, context: RouteContext) {
|
||||
try {
|
||||
const user = await requireAppUser();
|
||||
const { id } = await context.params;
|
||||
const template = await deleteImageTemplate(id, user.id);
|
||||
if (!template) return jsonError(new Error("模板不存在"), 404);
|
||||
return jsonOk({ template });
|
||||
} catch (error) {
|
||||
return jsonError(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user