From 9464a5c85f1537ec88005c9264f7a56f3ac3b63d Mon Sep 17 00:00:00 2001 From: abearxiong Date: Fri, 13 Feb 2026 19:15:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20GitHub=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=20API=20=E6=93=8D=E4=BD=9C=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E8=8E=B7=E5=8F=96=E3=80=81=E5=88=9B=E5=BB=BA=E3=80=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=92=8C=E5=88=A0=E9=99=A4=20starred=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convex/_generated/api.d.ts | 2 ++ convex/github/action.ts | 67 ++++++++++++++++++++++++++++++++++++++ convex/schema.ts | 15 +++++---- 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 convex/github/action.ts diff --git a/convex/_generated/api.d.ts b/convex/_generated/api.d.ts index d2336af..339832b 100644 --- a/convex/_generated/api.d.ts +++ b/convex/_generated/api.d.ts @@ -8,6 +8,7 @@ * @module */ +import type * as github_action from "../github/action.js"; import type * as github_starrred from "../github/starrred.js"; import type * as http from "../http.js"; @@ -18,6 +19,7 @@ import type { } from "convex/server"; declare const fullApi: ApiFromModules<{ + "github/action": typeof github_action; "github/starrred": typeof github_starrred; http: typeof http; }>; diff --git a/convex/github/action.ts b/convex/github/action.ts new file mode 100644 index 0000000..8b4e47a --- /dev/null +++ b/convex/github/action.ts @@ -0,0 +1,67 @@ +import { query, mutation, action } from "../_generated/server.js"; +import { v } from "convex/values"; + +export const getList = query({ + args: {}, + handler: async (ctx) => { + const results = await ctx.db.query("github_starred").collect(); + return results; + }, +}); + +export const createStarred = mutation({ + args: { + repo_id: v.number(), + title: v.string(), + description: v.string(), + author: v.string(), + stars: v.number(), + last_updated: v.string(), + link: v.string(), + auto: v.optional(v.string()), + summary: v.optional(v.string()), + tags: v.optional(v.array(v.string())), + }, + handler: async (ctx, values) => { + const repo_id = values.repo_id; + const existing = await ctx.db.query("github_starred").withIndex("by_repo_id", (q) => + q.eq("repo_id", repo_id) + ).first(); + if (existing) { + // 更新已有记录 + const updated = await ctx.db.patch("github_starred", existing._id, values); + return updated; + } + // 创建新记录 + const result = await ctx.db.insert("github_starred", values); + return result; + } +}); + +export const updateById = mutation({ + args: { + id: v.id("github_starred"), + repo_id: v.number(), + title: v.string(), + description: v.string(), + author: v.string(), + stars: v.number(), + last_updated: v.string(), + link: v.string(), + auto: v.optional(v.string()), + summary: v.optional(v.string()), + }, + handler: async (ctx, args) => { + const { id, ...rest } = args; + await ctx.db.patch(id, rest); + }, +}); + +export const deleteById = mutation({ + args: { + id: v.id("github_starred"), + }, + handler: async (ctx, args) => { + await ctx.db.delete(args.id); + }, +}); diff --git a/convex/schema.ts b/convex/schema.ts index 8d172cd..a62d4a9 100644 --- a/convex/schema.ts +++ b/convex/schema.ts @@ -4,16 +4,17 @@ import { v } from "convex/values"; export default defineSchema({ // Other tables here... github_starred: defineTable({ - author: v.string(), - auto: v.string(), + repo_id: v.number(), + title: v.string(), description: v.string(), + author: v.string(), + stars: v.number(), last_updated: v.string(), link: v.string(), - repo_id: v.float64(), - stars: v.float64(), - summary: v.string(), - title: v.string(), - }), + auto: v.optional(v.string()), + summary: v.optional(v.string()), + }).index("by_repo_id", ["repo_id"]) + .index("by_title", ["title"]), users: defineTable({ userId: v.string(), // 外部系统的用户 ID name: v.string(),