Handle connecting directly to the event stream URL

This commit is contained in:
Samuel Elliott
2022-11-16 12:13:48 +00:00
parent a52c45af36
commit 20bab43981
5 changed files with 30 additions and 2 deletions

View File

@@ -213,7 +213,7 @@ export type PresenceUrlResponse =
Friend | {friend: Friend};
export async function getPresenceFromUrl(presence_url: string, useragent?: string) {
const [signal, cancel] = timeoutSignal();
const [signal, cancel, controller] = timeoutSignal();
const response = await fetch(presence_url, {
headers: {
'User-Agent': getUserAgent(useragent),
@@ -227,6 +227,11 @@ export async function getPresenceFromUrl(presence_url: string, useragent?: strin
throw new ErrorResponse('[zncproxy] Unknown error', response, await response.text());
}
if (!response.headers.get('Content-Type')?.match(/^application\/json(;|$)$/)) {
controller.abort();
throw new ErrorResponse('[zncproxy] Unacceptable content type', response);
}
const data = await response.json() as PresenceUrlResponse;
const user: CurrentUser | Friend | undefined =