export type GetApiMatrixMediaV3ThumbnailServerNameMediaIdArgs = {serverName: unknown, mediaId: string, width: number, height: number, method?: ('crop' | 'scale') | undefined, allow_remote?: boolean | undefined, timeout_ms?: number | undefined, allow_redirect?: boolean | undefined, animated?: boolean | undefined}; export type GetApiMatrixMediaV3ThumbnailServerNameMediaIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download a thumbnail of content from the content repository * * GET /_matrix/media/v3/thumbnail/{serverName}/{mediaId} */ export const getApiMatrixMediaV3ThumbnailServerNameMediaId = async (args: GetApiMatrixMediaV3ThumbnailServerNameMediaIdArgs, options?: GetApiMatrixMediaV3ThumbnailServerNameMediaIdOptions) => { const {baseUrl = "https://matrix.org", fetch: fetchFn = fetch} = 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.allow_remote != null) query.append("allow_remote", String(args.allow_remote)) if (args.timeout_ms != null) query.append("timeout_ms", String(args.timeout_ms)) if (args.allow_redirect != null) query.append("allow_redirect", String(args.allow_redirect)) if (args.animated != null) query.append("animated", String(args.animated)) const url = `${baseUrl.replace(/\/+$/, '')}/_matrix/media/v3/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() };