fix mediamtx client
This commit is contained in:
@@ -31,8 +31,28 @@ class MediaMTXClient:
|
|||||||
json=payload,
|
json=payload,
|
||||||
auth=self._auth(),
|
auth=self._auth(),
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
if r.status_code != 404:
|
||||||
return r.json()
|
r.raise_for_status()
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
# Backward-compatible fallback for MediaMTX versions that don't support bulk patch.
|
||||||
|
results: dict[str, Any] = {"fallback": []}
|
||||||
|
async with httpx.AsyncClient(timeout=10) as client:
|
||||||
|
for name in names:
|
||||||
|
rr = await client.patch(
|
||||||
|
f"{self.api_url}/v3/config/paths/patch/{name}",
|
||||||
|
json={"record": enabled},
|
||||||
|
auth=self._auth(),
|
||||||
|
)
|
||||||
|
if rr.status_code == 404:
|
||||||
|
rr = await client.post(
|
||||||
|
f"{self.api_url}/v3/config/paths/add/{name}",
|
||||||
|
json={"record": enabled},
|
||||||
|
auth=self._auth(),
|
||||||
|
)
|
||||||
|
rr.raise_for_status()
|
||||||
|
results["fallback"].append({"name": name, "status": rr.status_code})
|
||||||
|
return results
|
||||||
|
|
||||||
async def upsert_paths_sources_bulk(self, sources: dict[str, str]) -> dict[str, Any]:
|
async def upsert_paths_sources_bulk(self, sources: dict[str, str]) -> dict[str, Any]:
|
||||||
payload = {"paths": {name: {"source": url} for name, url in sources.items()}}
|
payload = {"paths": {name: {"source": url} for name, url in sources.items()}}
|
||||||
|
|||||||
Reference in New Issue
Block a user