2026-05-25: 等级体系升级(20级)+论坛二级分类+会员空间
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const tasks = [
|
||||
{ taskKey: "task1-discover-tools", taskName: "发现AI工具", cronExpr: "0 6 * * *", enabled: true, desc: "每天从多源搜索新AI工具,过滤去重后入库等待审核" },
|
||||
{ taskKey: "task3-check-tools", taskName: "工具巡检", cronExpr: "0 3 * * *", enabled: true, desc: "检查所有已入库工具的网站可用性、Logo完整性、自动发布合格工具" },
|
||||
{ taskKey: "task4-discover-skills", taskName: "发现AI技能", cronExpr: "0 2 * * *", enabled: true, desc: "从GitHub搜索热门AI开源项目(≥1000 stars),获取README并入库" },
|
||||
{ taskKey: "task5-update-stars", taskName: "更新星值", cronExpr: "0 1 * * *", enabled: true, desc: "更新所有GitHub技能的最新Stars数,计算日/周/月变化趋势" },
|
||||
{ taskKey: "task6-review-hot", taskName: "评测热门", cronExpr: "0 4 * * *", enabled: true, desc: "对未评测的最热门2个AI技能进行五维深度评测并自动发布" },
|
||||
{ taskKey: "daily-news", taskName: "AI日报生成", cronExpr: "30 7 * * *", enabled: true, desc: "搜索真实新闻素材,AI整理格式生成当日AI日报" },
|
||||
];
|
||||
|
||||
const configs = await prisma.taskConfig.findMany();
|
||||
const configMap = new Map(configs.map((c) => [c.taskKey, c]));
|
||||
|
||||
const merged = tasks.map((t) => {
|
||||
const cfg = configMap.get(t.taskKey);
|
||||
return {
|
||||
taskKey: t.taskKey,
|
||||
taskName: t.taskName,
|
||||
cronExpr: cfg?.cronExpr || t.cronExpr,
|
||||
enabled: cfg?.enabled ?? t.enabled,
|
||||
description: t.desc,
|
||||
config: cfg?.config || null,
|
||||
updatedAt: cfg?.updatedAt?.toISOString() || null,
|
||||
};
|
||||
});
|
||||
|
||||
return NextResponse.json({ tasks: merged });
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const taskKey = body.taskKey as string;
|
||||
const { enabled, cronExpr, config } = body;
|
||||
|
||||
if (!taskKey) {
|
||||
return NextResponse.json({ error: "缺少taskKey" }, { status: 400 });
|
||||
}
|
||||
|
||||
const existing = await prisma.taskConfig.findUnique({ where: { taskKey } });
|
||||
let result;
|
||||
|
||||
if (existing) {
|
||||
result = await prisma.taskConfig.update({
|
||||
where: { taskKey },
|
||||
data: {
|
||||
enabled: enabled ?? existing.enabled,
|
||||
cronExpr: cronExpr ?? existing.cronExpr,
|
||||
config: config ?? existing.config,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const taskMeta: Record<string, string> = {
|
||||
"task1-discover-tools": "发现AI工具",
|
||||
"task3-check-tools": "工具巡检",
|
||||
"task4-discover-skills": "发现AI技能",
|
||||
"task5-update-stars": "更新星值",
|
||||
"task6-review-hot": "评测热门",
|
||||
"daily-news": "AI日报生成",
|
||||
};
|
||||
result = await prisma.taskConfig.create({
|
||||
data: {
|
||||
taskKey,
|
||||
taskName: taskMeta[taskKey] || taskKey,
|
||||
enabled: enabled ?? true,
|
||||
cronExpr: cronExpr || null,
|
||||
config: config || null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ task: result });
|
||||
} catch (error: unknown) {
|
||||
const err = error as { message?: string };
|
||||
return NextResponse.json({ error: err.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user