refactor: favicon 移回 app/ + 删除用户改为 RESTful DELETE /api/users/[id]

- favicon: 从 public/favicon.ico 移回 app/favicon.ico(next-on-pages 1.13.16 下生产验证 /favicon.ico 正常返回)
- 删除用户: POST /api/roles/delete 改为 DELETE /api/users/[id],符合 RESTful 语义(资源 users + 标准 DELETE 方法)
This commit is contained in:
stevenlee87
2026-07-30 22:09:33 +08:00
committed by BeilunYang
parent d34bb3d474
commit 4960395777
3 changed files with 9 additions and 8 deletions
@@ -7,14 +7,17 @@ import { getUserId } from "@/lib/apiKey";
export const runtime = "edge"; export const runtime = "edge";
export async function POST(request: Request) { export async function DELETE(
request: Request,
{ params }: { params: Promise<{ id: string }> }
) {
const canManage = await checkPermission(PERMISSIONS.PROMOTE_USER); const canManage = await checkPermission(PERMISSIONS.PROMOTE_USER);
if (!canManage) { if (!canManage) {
return Response.json({ error: "权限不足" }, { status: 403 }); return Response.json({ error: "权限不足" }, { status: 403 });
} }
try { try {
const { userId } = await request.json() as { userId: string }; const { id: userId } = await params;
if (!userId) { if (!userId) {
return Response.json({ error: "缺少必要参数" }, { status: 400 }); return Response.json({ error: "缺少必要参数" }, { status: 400 });
} }
@@ -26,14 +29,14 @@ export async function POST(request: Request) {
const db = createDb(); const db = createDb();
const currentUserRole = await db.query.userRoles.findFirst({ const targetUserRole = await db.query.userRoles.findFirst({
where: eq(userRoles.userId, userId), where: eq(userRoles.userId, userId),
with: { with: {
role: true, role: true,
}, },
}); });
if (currentUserRole?.role.name === ROLES.EMPEROR) { if (targetUserRole?.role.name === ROLES.EMPEROR) {
return Response.json({ error: "不能删除皇帝" }, { status: 400 }); return Response.json({ error: "不能删除皇帝" }, { status: 400 });
} }
+2 -4
View File
@@ -135,10 +135,8 @@ export function PromotePanel() {
const handleDelete = async (user: UserItem) => { const handleDelete = async (user: UserItem) => {
setDeletingUserId(user.id) setDeletingUserId(user.id)
try { try {
const res = await fetch("/api/roles/delete", { const res = await fetch(`/api/users/${user.id}`, {
method: "POST", method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ userId: user.id }),
}) })
if (!res.ok) { if (!res.ok) {
const error = await res.json() as { error: string } const error = await res.json() as { error: string }

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB