fix: align PR button custom_id with parser, secure token deletion, load zh locale

This commit is contained in:
RhenCloud 2026-08-09 00:13:02 +08:00
parent 589558a20d
commit 9f875e3180
3 changed files with 9 additions and 4 deletions

View file

@ -84,11 +84,12 @@ export function formatPullRequest(
}); });
} }
const actionable = pr.state === "open" && !!repo && pr.number != null; const [repoOwner, repoName] = (repo ?? "/").split("/", 2);
const actionable = pr.state === "open" && !!repoOwner && !!repoName && pr.number != null;
const actions: NeutralAction[] | undefined = actionable const actions: NeutralAction[] | undefined = actionable
? [ ? [
{ id: `ghpr|merge|${repo}|${pr.number}`, label: "合并", style: "primary" }, { id: `ghpr|merge|${repoOwner}|${repoName}|${pr.number}`, label: "合并", style: "primary" },
{ id: `ghpr|close|${repo}|${pr.number}`, label: "关闭", style: "danger" }, { id: `ghpr|close|${repoOwner}|${repoName}|${pr.number}`, label: "关闭", style: "danger" },
] ]
: undefined; : undefined;

View file

@ -1,4 +1,5 @@
import { en } from "./locales/en"; import { en } from "./locales/en";
import { zh } from "./locales/zh";
type NestedStrings = { [key: string]: string | NestedStrings }; type NestedStrings = { [key: string]: string | NestedStrings };
export type Translations = NestedStrings; export type Translations = NestedStrings;
@ -26,6 +27,7 @@ export async function loadTranslations(
kv?: { get<T>(key: string, type: "json"): Promise<T | null> }, kv?: { get<T>(key: string, type: "json"): Promise<T | null> },
): Promise<Translations> { ): Promise<Translations> {
if (lang === "en") return en; if (lang === "en") return en;
if (lang === "zh") return zh;
const cached = cache.get(lang); const cached = cache.get(lang);
if (cached) return cached; if (cached) return cached;

View file

@ -1,7 +1,7 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { getOAuthURL, handleOAuthCallback } from "../github/oauth"; import { getOAuthURL, handleOAuthCallback } from "../github/oauth";
import { removeToken, saveDiscordLink, saveTelegramLink } from "../github/store"; import { removeToken, saveDiscordLink, saveTelegramLink } from "../github/store";
import { createAdminSession, adminCookie } from "./session"; import { createAdminSession, adminCookie, getAdminSession } from "./session";
import { loadGroups, resolveScope, hasAnyAccess } from "./groups"; import { loadGroups, resolveScope, hasAnyAccess } from "./groups";
import { sendMessage } from "../drivers/telegram/rest"; import { sendMessage } from "../drivers/telegram/rest";
import type { Env } from "../types"; import type { Env } from "../types";
@ -127,6 +127,8 @@ export function createOAuthRoutes(): Hono<{ Bindings: Env }> {
}); });
app.delete("/token/:userId", async (c) => { app.delete("/token/:userId", async (c) => {
const session = await getAdminSession(c.env.KV, c.req.header("Cookie"));
if (!session) return c.json({ error: "Unauthorized" }, 401);
await removeToken(c.env.KV, c.req.param("userId")); await removeToken(c.env.KV, c.req.param("userId"));
return c.json({ ok: true }); return c.json({ ok: true });
}); });