feat(web): 渠道配置面板重做(按模式动态显隐 + 下拉 + 真鉴权键 + 掩码不回填)
新增:channelFieldRules.ts(纯函数规则层:选择器归一化 / 按 transport×mode 显隐与必填 /
写回补丁 / 模式提示文案)、channelConnFields.tsx(「连接配置」区:只渲染当前组合生效的字段,
逐字段「谁连谁」说明 + 必填/可选标记 + 掩码清除开关)、channelAccountId.tsx(账号 id 与
「覆盖/新建」状态 Tag)、channelPersonaField.tsx(从表单抽出,逻辑逐字保留)。
qq-obv11:transport / mode 改下拉;remote_url 仅 ws+client 显示且必填;listen_addr 按
server / http+client 条件显示;api_base_url 仅 http(http+client 必填);report_path 仅 http;
access_token 掩码;self_id 仅记录。每种组合顶部一句 modeHints;保存前拦截必填缺失并红框点名。
⚠️ 修掉一处数据毁伤:后端把 access_token 掩码成 ****abcd 下发,旧代码回填进表单 ⇒
「打开就保存」会把掩码写成真 token。现在掩码不回填、只记 configuredKeys,并提示
「已配置,留空 = 不改动」;要清空必须显式打开「清除已配置的 access_token」开关
(顺带给掩码秘密补上了以前没有的「清除」能力)。可见字段清空发 ""、隐藏字段不进补丁(缺位 = 保留)。
Token 误导修掉:PLATFORM_GUIDE.authKey 声明平台真正读取的键 —— qq-obv11 不再渲染 bot_token
输入框、不再标必填(改指向 access_token);渠道列表与只读配置卡的凭据行同步改用真实 authKey。
空 id:结论是后端契约(UpsertChannel 空 id = 新建),前端不碰后端修好:记住 savedId
(留空 = 覆盖当前条目)+ 改新 id 时内联二次确认 + 保存后用返回的 accountId 刷新 + 状态 Tag。
测试:新增真组件 SSR 渲染测试(68 checks)+ 规则单测(58 checks);17 个前端测试文件逐跑全绿;
tsc --noEmit 与 npm run build 通过(产物 index-CK_2RXKo.js)。
This commit is contained in:
1 parent
8c437866e7
commit
c4ea02a887
12 files changed
+1358
-132
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import type { AdminChannelRecord } from "../../../lib/types";
|
||||
import { PLATFORM_FIELDS } from "../channelFields";
|
||||
import { defaultSelection } from "../channelFieldRules";
|
||||
import { channelPersonaOf } from "./channelPersona";
|
||||
import type { ChannelConfigInitial } from "../channelConfigForm";
|
||||
|
||||
@@ -22,27 +23,64 @@ export interface CfgTarget {
|
||||
initial: ChannelConfigInitial;
|
||||
}
|
||||
|
||||
/** 后端对 token/secret/key 类键只下发掩码(`runtimeconfig.Masked`:`****` + 末 4 位)。
|
||||
* 掩码值**绝不能回填到表单**:一次「打开就保存」会把 `****abcd` 当成真实 token 写回,
|
||||
* 静默毁掉已配置的凭据。旧后端还用过「…(已配置)」这种文字掩码,一并容忍。 */
|
||||
export function isMaskedSecret(value: unknown): boolean {
|
||||
if (typeof value !== "string") return false;
|
||||
return value.startsWith("****") || value.includes("(已配置");
|
||||
}
|
||||
|
||||
/** 盘上该键是否已有非空值(不回填掩码原文,但仍要让面板知道「已配置」)。 */
|
||||
function hasStoredValue(raw: unknown): boolean {
|
||||
if (raw === null || raw === undefined) return false;
|
||||
if (typeof raw === "string") return raw.trim() !== "";
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Build the config-form prefill from a platform name and the channel records.
|
||||
* Do NOT put the masked placeholder into `token`: it would be written back as
|
||||
* the real bot_token (overwriting the stored secret with a demo string). Keep
|
||||
* token empty (save omits it → keeps the existing secret) and show a hint. */
|
||||
export function buildCfgTarget(name: string, records: AdminChannelRecord[]): CfgTarget {
|
||||
* token empty (save omits it → keeps the existing secret) and show a hint.
|
||||
*
|
||||
* 平台字段同理:掩码值不回填,只记进 `configuredKeys`(表单据此显示「已配置、留空不
|
||||
* 改动」并把它当作需求已满足);下拉型选择器(transport/mode)在盘上缺值时填默认值,
|
||||
* 这样打开表单第一眼看到的组合就是适配器真正会用的那个。 */
|
||||
export function buildCfgTarget(name: string, records: AdminChannelRecord[], accountId?: string): CfgTarget {
|
||||
const plat = platformOf(name);
|
||||
const acct = records.find((c) => platformOf(c.name) === plat)?.accounts?.[0];
|
||||
const accts = records.find((c) => platformOf(c.name) === plat)?.accounts ?? [];
|
||||
// 指定账号优先(多账号平台逐条编辑);未指定时退回第一个,与旧行为一致。
|
||||
const acct = (accountId ? accts.find((a) => a.id === accountId) : undefined) ?? accts[0];
|
||||
const acctCfg = acct?.config ?? {};
|
||||
const hasToken = typeof acctCfg.bot_token === "string" && acctCfg.bot_token && !acctCfg.bot_token.includes("(已配置");
|
||||
const hasToken = typeof acctCfg.bot_token === "string" && acctCfg.bot_token && !isMaskedSecret(acctCfg.bot_token);
|
||||
const fieldDefs = PLATFORM_FIELDS[plat] ?? [];
|
||||
const platVals: Record<string, string> = {};
|
||||
for (const f of PLATFORM_FIELDS[plat] ?? []) {
|
||||
const v = acctCfg[f.key];
|
||||
platVals[f.key] = v == null ? "" : String(v);
|
||||
const configuredKeys: string[] = [];
|
||||
for (const f of fieldDefs) {
|
||||
const raw = acctCfg[f.key];
|
||||
if (!hasStoredValue(raw)) continue;
|
||||
configuredKeys.push(f.key);
|
||||
if (isMaskedSecret(raw)) continue;
|
||||
platVals[f.key] = String(raw);
|
||||
}
|
||||
const fallback = defaultSelection(plat);
|
||||
for (const f of fieldDefs) {
|
||||
if (platVals[f.key] !== undefined) continue;
|
||||
const def = f.defaultValue ?? "";
|
||||
if (def !== "") platVals[f.key] = def;
|
||||
}
|
||||
// 选择器缺省兜底:即使平台没给字段声明缺省值,也让「当前模式」有值可判定。
|
||||
if (fallback.transport && platVals.transport === undefined) platVals.transport = fallback.transport;
|
||||
if (fallback.mode && platVals.mode === undefined) platVals.mode = fallback.mode;
|
||||
return {
|
||||
platform: plat,
|
||||
initial: {
|
||||
accountId: acct?.id ?? "",
|
||||
savedId: acct?.id ?? "",
|
||||
tokenHint: hasToken ? "已配置(仅掩码显示),留空则不改动;如需更换请重新输入。" : "",
|
||||
baseURL: typeof acctCfg.base_url === "string" ? acctCfg.base_url : "",
|
||||
platVals,
|
||||
configuredKeys,
|
||||
allowGroups: (acct?.allowGroups ?? []).join(","),
|
||||
denyGroups: (acct?.denyGroups ?? []).join(","),
|
||||
allowUsers: (acct?.allowUsers ?? []).join(","),
|
||||
|
||||
Reference in new issue
Block a user