Files
MeBox/web/src/api/dlna.ts
T
soldosluka857 b2ccd04844 fix(dlna): always return non-nil device slice so API serializes [] not null
The DLNA device list endpoint could return {"devices":null} in two cases:
the SSDP-failure path returned a nil slice, and the cached path copied an
empty cache via append([]DLNADevice(nil), cache...) which also yields nil.
The web UI reads res.devices.length, so a null devices field crashed the
DLNA page to a white screen. Return non-nil slices in both paths and guard
the frontend with a null coalesce. Adds a regression test.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-05-30 13:02:16 +08:00

24 lines
582 B
TypeScript

import { api } from './client'
export interface DLNADevice {
udn: string
friendly_name: string
manufacturer: string
model_name: string
location: string
control_url: string
ip_address: string
}
export const dlnaAPI = {
list: (force = false) =>
api
.get<{ devices: DLNADevice[] | null }>('/dlna/devices', { params: { force: force ? 'true' : '' } })
.then((r) => r.data.devices ?? []),
cast: (controlURL: string, mediaURL: string) =>
api
.post('/dlna/cast', { control_url: controlURL, media_url: mediaURL })
.then((r) => r.data),
}