export type GetApiMatrixMediaV3DownloadServerNameMediaIdFileNameArgs = {serverName: unknown, mediaId: string, fileName: string, allow_remote?: boolean | undefined, timeout_ms?: number | undefined, allow_redirect?: boolean | undefined}; export type GetApiMatrixMediaV3DownloadServerNameMediaIdFileNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download content from the content repository overriding the file name * * GET /_matrix/media/v3/download/{serverName}/{mediaId}/{fileName} */ export const getApiMatrixMediaV3DownloadServerNameMediaIdFileName = async (args: GetApiMatrixMediaV3DownloadServerNameMediaIdFileNameArgs, options?: GetApiMatrixMediaV3DownloadServerNameMediaIdFileNameOptions) => { const {baseUrl = "https://matrix.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") 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)) const url = `${baseUrl.replace(/\/+$/, '')}/_matrix/media/v3/download/${encodeURIComponent(String(args.serverName))}/${encodeURIComponent(String(args.mediaId))}/${encodeURIComponent(String(args.fileName))}${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() };