v0.11.1: 权限体系重构 + AI管线优化 + 内容整理
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireAdmin } from "@/lib/admin-auth";
|
||||
|
||||
function generateSlug(name: string): string {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\u4e00-\u9fa5]+/g, "-")
|
||||
.replace(/^-|-$/g, "")
|
||||
|| "tool";
|
||||
}
|
||||
|
||||
function pinyinSlug(name: string): string {
|
||||
const map: Record<string, string> = {
|
||||
"文本生成": "text-generation", "图像生成": "image-generation",
|
||||
"视频生成": "video-generation", "音频处理": "audio-processing",
|
||||
"代码助手": "code-assistant", "办公效率": "office-efficiency",
|
||||
"AI 角色": "ai-character", "设计工具": "design-tools",
|
||||
"数据分析": "data-analysis", "内容检测": "content-detection",
|
||||
};
|
||||
if (map[name]) return map[name];
|
||||
const slug = generateSlug(name);
|
||||
if (/^[a-z0-9-]+$/.test(slug)) return slug;
|
||||
return "tool-" + Date.now().toString(36);
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
_request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const authError = await requireAdmin();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const id = parseInt(params.id);
|
||||
|
||||
const pending = await prisma.pendingTool.findUnique({ where: { id } });
|
||||
if (!pending) {
|
||||
return NextResponse.json({ error: "待审核工具不存在" }, { status: 404 });
|
||||
}
|
||||
|
||||
let slug = pinyinSlug(pending.name);
|
||||
const existing = await prisma.tool.findUnique({ where: { slug } });
|
||||
if (existing) {
|
||||
slug = slug + "-" + Math.floor(Math.random() * 10000);
|
||||
}
|
||||
|
||||
const categoryId = pending.categoryId ?? ((
|
||||
await prisma.category.findFirst({ orderBy: { sortOrder: "asc" } })
|
||||
)?.id ?? 1);
|
||||
|
||||
const tool = await prisma.tool.create({
|
||||
data: {
|
||||
name: pending.name,
|
||||
slug,
|
||||
categoryId,
|
||||
description: pending.description ?? "",
|
||||
logoUrl: pending.logoUrl,
|
||||
websiteUrl: pending.websiteUrl ?? "",
|
||||
pricingModel: pending.pricingModel ?? "freemium",
|
||||
pricingDetail: pending.pricingDetail,
|
||||
features: pending.features as any,
|
||||
tags: pending.tags as any,
|
||||
status: "published",
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.pendingTool.delete({ where: { id } });
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
toolId: tool.id,
|
||||
message: "发布成功",
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user