新增 build:test 方便构建线上的测试环境,优化分享码功能的交互

This commit is contained in:
eafonyang
2026-06-17 16:51:36 +08:00
parent 7eb7647484
commit 8d369412fd
12 changed files with 213 additions and 18 deletions
+46 -3
View File
@@ -673,6 +673,26 @@ export async function fetchLuxsinAudioCurve(
// Share Code API — shareCreate / shareList / shareQuery / shareAccept
// ============================================================
const SHARE_DEVICE_MODELS = ["Luxsin-X9", "Luxsin-X8"] as const;
export type ShareDeviceModel = (typeof SHARE_DEVICE_MODELS)[number];
/** Map DeviceState.device to app-api share code model enum. */
export function resolveShareDeviceModel(device: string): ShareDeviceModel | null {
const trimmed = device.trim();
if ((SHARE_DEVICE_MODELS as readonly string[]).includes(trimmed)) {
return trimmed as ShareDeviceModel;
}
const hyphenated = trimmed.replace(/\s+/g, "-");
if ((SHARE_DEVICE_MODELS as readonly string[]).includes(hyphenated)) {
return hyphenated as ShareDeviceModel;
}
const lower = trimmed.toLowerCase();
if (lower.includes("x9")) return "Luxsin-X9";
if (lower.includes("x8")) return "Luxsin-X8";
return null;
}
export interface ShareCodeCreateResponse {
code: number;
msg: string;
@@ -697,6 +717,7 @@ export interface ShareCodeAcceptResponse {
code: number;
msg: string;
eq_data?: Record<string, unknown>;
model?: string;
}
export interface ShareCodeQueryResponse {
@@ -704,6 +725,7 @@ export interface ShareCodeQueryResponse {
msg: string;
eq_data?: Record<string, unknown>;
expire_at?: string;
model?: string;
}
/** Unwrap stringified PEQ filters (remove JSON escape layers) for API submit. */
@@ -727,6 +749,7 @@ export function normalizePeqFiltersForSubmit(filters: unknown): PeqFilter[] {
/** POST `/audio/shareCreate` — 创建 EQ 分享码,返回 share_code + expire_at + eq_data */
export async function createShareCode(
mac: string,
model: ShareDeviceModel,
eqData: Record<string, unknown>,
): Promise<ShareCodeCreateResponse> {
const payload = {
@@ -738,7 +761,7 @@ export async function createShareCode(
const res = await fetch(buildLuxsinAudioUrl("shareCreate"), {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ mac, eq_data: payload }),
body: JSON.stringify({ mac, model, eq_data: payload }),
});
if (!res.ok) throw new Error(`shareCreate HTTP ${res.status}`);
return (await res.json()) as ShareCodeCreateResponse;
@@ -762,16 +785,36 @@ export async function queryShareCode(shareCode: string): Promise<ShareCodeQueryR
return (await res.json()) as ShareCodeQueryResponse;
}
/** GET `/audio/shareAccept?mac=...&shareCode=...` — 确认导入分享码并记录流水 */
/** GET `/audio/shareAccept?mac=...&model=...&shareCode=...` — 确认导入分享码并记录流水 */
export async function acceptShareCode(
mac: string,
model: ShareDeviceModel,
shareCode: string,
): Promise<ShareCodeAcceptResponse> {
const res = await fetch(
buildLuxsinAudioUrl(
`shareAccept?mac=${encodeURIComponent(mac)}&shareCode=${encodeURIComponent(shareCode)}`,
`shareAccept?mac=${encodeURIComponent(mac)}&model=${encodeURIComponent(model)}&shareCode=${encodeURIComponent(shareCode)}`,
),
);
if (!res.ok) throw new Error(`shareAccept HTTP ${res.status}`);
return (await res.json()) as ShareCodeAcceptResponse;
}
export interface ShareCodeDeleteResponse {
code: number;
msg: string;
}
/** GET `/audio/shareDelete?mac=...&shareCode=...` — 删除分享码 */
export async function deleteShareCode(
mac: string,
shareCode: string,
): Promise<ShareCodeDeleteResponse> {
const res = await fetch(
buildLuxsinAudioUrl(
`shareDelete?mac=${encodeURIComponent(mac)}&shareCode=${encodeURIComponent(shareCode)}`,
),
);
if (!res.ok) throw new Error(`shareDelete HTTP ${res.status}`);
return (await res.json()) as ShareCodeDeleteResponse;
}