export type GetApiAvatarStreamedIdUserIdArgs = {userId: string}; export type GetApiAvatarStreamedIdUserIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Microsoft doesn't provide a public URL for fetching profile photos / avatars so we have to stream them. * * GET /avatar/streamed/id/{userId} */ export const getApiAvatarStreamedIdUserId = async (args: GetApiAvatarStreamedIdUserIdArgs, options: GetApiAvatarStreamedIdUserIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/jpeg") const url = `${baseUrl.replace(/\/+$/, '')}/avatar/streamed/id/${encodeURIComponent(String(args.userId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };