diff --git a/apps/ui/src/App.tsx b/apps/ui/src/App.tsx index e6f9402..0aacd4d 100644 --- a/apps/ui/src/App.tsx +++ b/apps/ui/src/App.tsx @@ -497,7 +497,7 @@ const App = () => { try { await navigator.clipboard.writeText(result.token); setNotice(`令牌已复制到剪贴板:${result.token}`); - } catch (clipboardError) { + } catch (_clipboardError) { setNotice(`令牌: ${result.token}`); } } catch (error) { diff --git a/apps/worker/src/routes/newapiChannels.ts b/apps/worker/src/routes/newapiChannels.ts index 5ef24c4..315bf8e 100644 --- a/apps/worker/src/routes/newapiChannels.ts +++ b/apps/worker/src/routes/newapiChannels.ts @@ -1,14 +1,6 @@ import { type Context, Hono } from "hono"; import type { AppEnv } from "../env"; import { newApiAuth } from "../middleware/newApiAuth"; -import { - mergeMetadata, - modelsToJson, - normalizeBaseUrlInput, - normalizeChannelInput, - toNewApiChannel, - withNewApiDefaults, -} from "../services/newapi"; import { collectUniqueModelIds, extractModelIds, @@ -28,6 +20,14 @@ import { fetchChannelModels, updateChannelTestResult, } from "../services/channel-testing"; +import { + mergeMetadata, + modelsToJson, + normalizeBaseUrlInput, + normalizeChannelInput, + toNewApiChannel, + withNewApiDefaults, +} from "../services/newapi"; import { generateToken } from "../utils/crypto"; import { safeJsonParse } from "../utils/json"; import { newApiFailure, newApiSuccess } from "../utils/newapi-response"; @@ -58,7 +58,6 @@ async function handleModelsList(c: Context) { return newApiSuccess(c, data); } - newapi.get("/", async (c) => { const page = normalizePage(c.req.query("p") ?? c.req.query("page"), 1); const pageSize = normalizePageSize( @@ -291,7 +290,7 @@ newapi.post("/", async (c) => { type: parsed.type ?? 1, group_name: parsed.group_name ?? null, priority: parsed.priority ?? 0, - metadata_json: parsed.metadata_json, + metadata_json: parsed.metadata_json ?? null, created_at: now, updated_at: now, }); @@ -489,4 +488,3 @@ newapi.get("/:id", async (c) => { }); export default newapi; - diff --git a/apps/worker/src/services/channel-repo.ts b/apps/worker/src/services/channel-repo.ts index 44e9a13..747c753 100644 --- a/apps/worker/src/services/channel-repo.ts +++ b/apps/worker/src/services/channel-repo.ts @@ -67,8 +67,10 @@ export async function listChannels( const statement = db.prepare( `SELECT * FROM channels ${whereSql} ${orderSql} ${limitSql}`, ); - const rows = await bindIfNeeded(statement, [...bindings, ...limitBindings]) - .all(); + const rows = await bindIfNeeded(statement, [ + ...bindings, + ...limitBindings, + ]).all(); return rows.results ?? []; } @@ -80,7 +82,9 @@ export async function countChannels( const statement = db.prepare( `SELECT COUNT(*) as count FROM channels ${whereSql}`, ); - const row = await bindIfNeeded(statement, bindings).first<{ count: number }>(); + const row = await bindIfNeeded(statement, bindings).first<{ + count: number; + }>(); return Number(row?.count ?? 0); } @@ -220,9 +224,6 @@ export async function updateChannel( .run(); } -export async function deleteChannel( - db: D1Database, - id: string, -): Promise { +export async function deleteChannel(db: D1Database, id: string): Promise { await db.prepare("DELETE FROM channels WHERE id = ?").bind(id).run(); } diff --git a/apps/worker/src/services/channel-testing.ts b/apps/worker/src/services/channel-testing.ts index 7621983..343adf0 100644 --- a/apps/worker/src/services/channel-testing.ts +++ b/apps/worker/src/services/channel-testing.ts @@ -1,7 +1,7 @@ import type { D1Database } from "@cloudflare/workers-types"; import { nowIso } from "../utils/time"; import { normalizeBaseUrl } from "../utils/url"; -import { normalizeModelsInput, modelsToJson } from "./channel-models"; +import { modelsToJson, normalizeModelsInput } from "./channel-models"; export type ChannelTestResult = { ok: boolean; @@ -52,14 +52,17 @@ export async function updateChannelTestResult( const now = Math.floor(Date.now() / 1000); const status = result.ok ? "active" : "error"; const modelsJson = - result.modelsJson ?? (result.models ? modelsToJson(result.models) : undefined); + result.modelsJson ?? + (result.models ? modelsToJson(result.models) : undefined); const sql = modelsJson ? "UPDATE channels SET status = ?, models_json = ?, test_time = ?, response_time_ms = ?, updated_at = ? WHERE id = ?" : "UPDATE channels SET status = ?, test_time = ?, response_time_ms = ?, updated_at = ? WHERE id = ?"; const stmt = db.prepare(sql); if (modelsJson) { - await stmt.bind(status, modelsJson, now, result.elapsed, nowIso(), id).run(); + await stmt + .bind(status, modelsJson, now, result.elapsed, nowIso(), id) + .run(); } else { await stmt.bind(status, now, result.elapsed, nowIso(), id).run(); } diff --git a/apps/worker/src/services/channels.ts b/apps/worker/src/services/channels.ts index f095b54..37837c7 100644 --- a/apps/worker/src/services/channels.ts +++ b/apps/worker/src/services/channels.ts @@ -1,8 +1,8 @@ -import type { ChannelRecord } from "./channel-types"; import { extractModels } from "./channel-models"; +import type { ChannelRecord } from "./channel-types"; -export type { ChannelRecord } from "./channel-types"; export type { ModelEntry } from "./channel-models"; +export type { ChannelRecord } from "./channel-types"; export { extractModels }; /** diff --git a/apps/worker/src/services/newapi.ts b/apps/worker/src/services/newapi.ts index b94a4f6..e2b92e0 100644 --- a/apps/worker/src/services/newapi.ts +++ b/apps/worker/src/services/newapi.ts @@ -1,12 +1,12 @@ import { safeJsonParse } from "../utils/json"; import { normalizeBaseUrl } from "../utils/url"; -import type { ChannelRow } from "./channel-types"; import { extractModelIds, modelsToJson, normalizeModelsInput, } from "./channel-models"; import { toInternalStatus, toNewApiStatus } from "./channel-status"; +import type { ChannelRow } from "./channel-types"; export { extractModelIds, modelsToJson, normalizeModelsInput }; export { toInternalStatus, toNewApiStatus }; diff --git a/helloagents/CHANGELOG.md b/helloagents/CHANGELOG.md index dc3b715..ee2b9b3 100644 --- a/helloagents/CHANGELOG.md +++ b/helloagents/CHANGELOG.md @@ -3,6 +3,12 @@ ## [Unreleased] ### 微调 +- **[admin-ui]**: 处理剪贴板异常时忽略未使用的错误变量 + - 类型: 微调(无方案包) + - 文件: apps/ui/src/App.tsx:500 +- **[worker]**: 创建渠道时 metadata_json 为空则写入 null 以满足类型约束 + - 类型: 微调(无方案包) + - 文件: apps/worker/src/routes/newapiChannels.ts:293 - **[admin-ui]**: 令牌查看自动复制并提示 - 类型: 微调(无方案包) - 文件: apps/ui/src/App.tsx:440-455