import { PrismaClient } from "@prisma/client"; import { PrismaMariaDb } from "@prisma/adapter-mariadb"; import "dotenv/config"; const base = process.env.DATABASE_URL || "mysql://localhost:3306/zhuiguang_ai?charset=utf8mb4"; const sep = base.includes("?") ? "&" : "?"; const connectionString = `${base}${sep}connection_limit=20&pool_timeout=30`; const adapter = new PrismaMariaDb(connectionString); const prisma = new PrismaClient({ adapter }); const TASK_DEFS = [ { taskKey: "task1-discover-tools", taskName: "发现AI工具", enabled: true, cronExpr: "0 6 * * *", description: "每天早上6点从36kr/IT之家/开源中国RSS抓取新闻,由DeepSeek提取AI工具信息并入库待审核", config: { sources: ["36kr", "IT之家", "开源中国"], model: "deepseek-v4-pro" }, }, { taskKey: "task3-check-tools", taskName: "工具巡检", enabled: true, cronExpr: "0 3 * * *", description: "每天凌晨3点检查所有已发布工具的网站可访问性和Logo有效性,自动发布通过检查的待审核工具", config: { checkWebsite: true, checkLogo: true, autoPublish: true }, }, { taskKey: "task4-discover-skills", taskName: "发现AI技能", enabled: true, cronExpr: "0 5 * * *", description: "每天凌晨5点从GitHub搜索高星AI项目(stars≥1000),DeepSeek预评测后入库PendingSkill待审核", config: { minStars: 1000, dailyLimit: 30, model: "deepseek-v4-pro" }, }, { taskKey: "task5-update-stars", taskName: "更新技能星值", enabled: true, cronExpr: "0 1 * * *", description: "每天凌晨1点更新所有GitHub技能的最新Stars数,记录日/周/月变化趋势", config: { updateAll: true, historyDays: 90 }, }, { taskKey: "task6-review-hot", taskName: "评测热门技能", enabled: true, cronExpr: "0 4 * * *", description: "每天凌晨4点对2个最热门且未评测的GitHub技能进行五维深度评测,自动生成SkillReview", config: { dailyLimit: 2, model: "deepseek-v4-pro" }, }, { taskKey: "daily-news", taskName: "AI日报生成", enabled: true, cronExpr: "30 7 * * *", description: "每天早上7:30从多源RSS搜索真实AI新闻,由DeepSeek整理格式生成当日日报", config: { sources: ["36kr", "IT之家", "开源中国", "GoogleNews", "HackerNews"], model: "deepseek-v4-pro" }, }, ]; async function main() { console.log("🌱 初始化任务配置种子数据...\n"); let created = 0; let updated = 0; for (const def of TASK_DEFS) { const existing = await prisma.taskConfig.findUnique({ where: { taskKey: def.taskKey }, }); if (existing) { await prisma.taskConfig.update({ where: { taskKey: def.taskKey }, data: { taskName: def.taskName, cronExpr: def.cronExpr, description: def.description, config: def.config, }, }); updated++; console.log(` 🔄 更新: ${def.taskName} (${def.taskKey})`); } else { await prisma.taskConfig.create({ data: { taskKey: def.taskKey, taskName: def.taskName, enabled: def.enabled, cronExpr: def.cronExpr, description: def.description, config: def.config, }, }); created++; console.log(` ✅ 创建: ${def.taskName} (${def.taskKey})`); } } console.log(`\n🏁 完成: 创建${created}个, 更新${updated}个`); await prisma.$disconnect(); } main().catch(async (e) => { console.error("❌ 种子数据初始化失败:", e.message); if (prisma) await prisma.$disconnect(); process.exit(1); });