export type GetApiMediaIdDataOptions = {baseUrl?: string | undefined, XFOAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a media item file * * GET /media/{id}/data * * Also accepts auth: XF-Api-Key */ export const getApiMediaIdData = async (options?: GetApiMediaIdDataOptions) => { const {baseUrl = "https://example.com/api", fetch: fetchFn = fetch, XFOAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (XFOAuth2 !== undefined) headers.set('authorization', `Bearer ${XFOAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/media/${encodeURIComponent(String(args.id))}/data${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 undefined };