新增 build:test 方便构建线上的测试环境,优化分享码功能的交互
This commit is contained in:
@@ -407,7 +407,7 @@ export function readBootSoundFromState(state: DeviceState | null | undefined): n
|
||||
// Mock data for demo/offline mode
|
||||
// ============================================================
|
||||
export const MOCK_DEVICE_STATE: DeviceState = {
|
||||
device: "Luxsin-X9",
|
||||
device: "Luxsin-X8",
|
||||
version: "1.2.3",
|
||||
mac: "AA:BB:CC:DD:EE:FF",
|
||||
language: 0,
|
||||
@@ -629,6 +629,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;
|
||||
@@ -653,6 +673,7 @@ export interface ShareCodeAcceptResponse {
|
||||
code: number;
|
||||
msg: string;
|
||||
eq_data?: Record<string, unknown>;
|
||||
model?: string;
|
||||
}
|
||||
|
||||
export interface ShareCodeQueryResponse {
|
||||
@@ -660,6 +681,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. */
|
||||
@@ -683,6 +705,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 = {
|
||||
@@ -694,7 +717,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;
|
||||
@@ -718,16 +741,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user