export type GetApiMatrixClientV1MediaThumbnailServerNameMediaIdArgs = {serverName: unknown, mediaId: string, width: number, height: number, method?: ('crop' | 'scale') | undefined, timeout_ms?: number | undefined, animated?: boolean | undefined}; export type GetApiMatrixClientV1MediaThumbnailServerNameMediaIdOptions = {baseUrl?: string | undefined, accessTokenQuery?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a thumbnail of content from the content repository * * GET /_matrix/client/v1/media/thumbnail/{serverName}/{mediaId} * * Also accepts auth: accessTokenBearer */ export const getApiMatrixClientV1MediaThumbnailServerNameMediaId = async (args: GetApiMatrixClientV1MediaThumbnailServerNameMediaIdArgs, options?: GetApiMatrixClientV1MediaThumbnailServerNameMediaIdOptions) => { const {baseUrl = "https://matrix.org", fetch: fetchFn = fetch, accessTokenQuery} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "image/apng") if (args.width != null) query.append("width", String(args.width)) if (args.height != null) query.append("height", String(args.height)) if (args.method != null) query.append("method", String(args.method)) if (args.timeout_ms != null) query.append("timeout_ms", String(args.timeout_ms)) if (args.animated != null) query.append("animated", String(args.animated)) if (accessTokenQuery !== undefined) query.set("access_token", accessTokenQuery) const url = `${baseUrl.replace(/\/+$/, '')}/_matrix/client/v1/media/thumbnail/${encodeURIComponent(String(args.serverName))}/${encodeURIComponent(String(args.mediaId))}${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() };