feat: 添加设备注册 API 并重构安装横幅组件
This commit is contained in:
40
app/api/v1/device/name/route.ts
Normal file
40
app/api/v1/device/name/route.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db";
|
||||
import { claws } from "@/lib/db/schema";
|
||||
import { authenticateRequest } from "@/lib/auth/request";
|
||||
import { updateNameSchema } from "@/lib/validators/schemas";
|
||||
|
||||
export async function PUT(req: NextRequest) {
|
||||
try {
|
||||
const auth = await authenticateRequest(req);
|
||||
if (auth instanceof NextResponse) {
|
||||
return auth;
|
||||
}
|
||||
const { claw } = auth;
|
||||
|
||||
const body = await req.json();
|
||||
const parsed = updateNameSchema.safeParse(body);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: "Validation failed", details: parsed.error.flatten() },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const { name } = parsed.data;
|
||||
|
||||
await db
|
||||
.update(claws)
|
||||
.set({ name, updatedAt: new Date() })
|
||||
.where(eq(claws.id, claw.id));
|
||||
|
||||
return NextResponse.json({ ok: true, name });
|
||||
} catch (error) {
|
||||
console.error("Update name error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Internal server error" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user