mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-09-07 02:45:09 -05:00
Handle connecting directly to the event stream URL
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user