fix webhooks errors
This commit is contained in:
parent
59325d4f2e
commit
cdb5b4fc55
30
main_app.py
30
main_app.py
@ -206,6 +206,36 @@ async def fake_claim_exchange(request: Request, _=host_required([Hosts.PLEX])):
|
||||
return await return_edited_response(upstream_response, data_override)
|
||||
|
||||
|
||||
@app.post("/api/v2/user/webhooks", tags=[Hosts.CLIENTS.value])
|
||||
async def fake_get_user_webhooks(request: Request, _=host_required([Hosts.CLIENTS])):
|
||||
# FIXME: this doesnt really work because webhooks are sent from Plex themselves so unless we implement a complete
|
||||
# webhook emitter this is kinda useless but at least removes errors from UI...
|
||||
|
||||
upstream_response = await call_official(request, request.url.path.lstrip("/"))
|
||||
|
||||
# body = await request.body()
|
||||
# raw_text = body.decode("utf-8")
|
||||
# parsed_urls = parse_qs(raw_text)
|
||||
# data_override = [
|
||||
# {"url": url} for url in parsed_urls.get("urls[]", [])
|
||||
# ]
|
||||
|
||||
data_override = [{"url": "https://webhooks.are.not.supported.because.plex.sends.them/not/your/server"}]
|
||||
|
||||
return await return_edited_response(upstream_response, data_override)
|
||||
|
||||
|
||||
@app.get("/api/v2/user/webhooks", tags=[Hosts.CLIENTS.value])
|
||||
async def fake_list_user_webhooks(request: Request, _=host_required([Hosts.CLIENTS])):
|
||||
# See note in POST /api/v2/user/webhooks
|
||||
|
||||
upstream_response = await call_official(request, request.url.path.lstrip("/"))
|
||||
|
||||
data_override = []
|
||||
|
||||
return await return_edited_response(upstream_response, data_override)
|
||||
|
||||
|
||||
@app.get("/favicon.ico")
|
||||
async def favicon():
|
||||
return FileResponse("favicon.ico")
|
||||
|
3
utils.py
3
utils.py
@ -18,6 +18,7 @@ official_client = httpx.AsyncClient(
|
||||
def host_required(allowed_hosts: list[Hosts]):
|
||||
async def dependency(request: Request):
|
||||
host = request.url.hostname
|
||||
if host != "localhost" and host != "127.0.0.1":
|
||||
if host not in [h.value for h in allowed_hosts]:
|
||||
logger.warning(f"Host '{host}' not allowed for url '{request.url}'")
|
||||
raise HTTPException(status_code=403, detail=f"Host '{host}' not allowed")
|
||||
@ -64,7 +65,7 @@ async def call_official(request: Request, path: str) -> httpx.Response:
|
||||
|
||||
async def return_edited_response(
|
||||
response: httpx.Response,
|
||||
new_content: dict | bytes | None = None
|
||||
new_content: dict | bytes | list | str | None = None
|
||||
) -> Response:
|
||||
"""
|
||||
Return possibly modified response.
|
||||
|
Loading…
x
Reference in New Issue
Block a user