refactor(voice): 语音配置改用新版 API Key 鉴权(弃旧版 appid+token)

用户提醒:火山新版走 API Key 鉴权,不用旧版 appid+access_token。新版 WS 握手只带两个
header——Authorization(Bearer <APIKey>) + X-Api-Resource-Id。

配置从 {appid, access_token, 2×resource-id, voice} 收敛为 {api_key, 2×resource-id,
voice}:APIKey 走 secrets AES 加密入库;ASREnabled/TTSEnabled 改为只看 api_key+对应
resource-id。admin 配置页两个字段并一个 API Key 字段,清单同步改为新版口径。build+tsc 绿。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Blizzard
2026-07-21 17:06:22 +08:00
parent 618184689e
commit a28ae49b6a
4 changed files with 36 additions and 50 deletions
+5 -6
View File
@@ -267,10 +267,9 @@ export async function saveWechatMP(body: { appid: string; app_secret: string; to
return { enabled: !!d.enabled };
}
// —— 语音(火山豆包)配置 ——
// —— 语音(火山豆包)配置 · 新版 API Key 鉴权 ——
export interface VoiceConfig {
appid: string;
access_token: string; // 明文回显(单管理员后台)
api_key: string; // 明文回显(单管理员后台)
asr_resource_id: string;
tts_resource_id: string;
tts_voice_type: string;
@@ -283,15 +282,15 @@ export async function getVoiceConfig(): Promise<VoiceConfig> {
const d = (await res.json().catch(() => ({}))) as Partial<VoiceConfig> & { error?: string };
if (!res.ok) throw new Error(d.error ?? `voice config failed: ${res.status}`);
return {
appid: d.appid ?? "", access_token: d.access_token ?? "", asr_resource_id: d.asr_resource_id ?? "",
api_key: d.api_key ?? "", asr_resource_id: d.asr_resource_id ?? "",
tts_resource_id: d.tts_resource_id ?? "", tts_voice_type: d.tts_voice_type ?? "",
asr_enabled: !!d.asr_enabled, tts_enabled: !!d.tts_enabled,
};
}
// access_token 传空串 = 沿用已保存的。
// api_key 传空串 = 沿用已保存的。
export async function saveVoiceConfig(body: {
appid: string; access_token: string; asr_resource_id: string; tts_resource_id: string; tts_voice_type: string;
api_key: string; asr_resource_id: string; tts_resource_id: string; tts_voice_type: string;
}): Promise<{ asr_enabled: boolean; tts_enabled: boolean }> {
const res = guard(await fetch(`${ADMIN}/voice`, { method: "PUT", headers: authHeaders(true), body: JSON.stringify(body) }));
const d = (await res.json().catch(() => ({}))) as { asr_enabled?: boolean; tts_enabled?: boolean; error?: string };