From 0e1c788f5b9648f5c01accdfe61c0d6928410dc8 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 12 Sep 2022 15:30:27 +0200 Subject: [PATCH] Use arrayBuffer for zip files (#3284) --- apps/admin-ui/src/clients/ClientDetails.tsx | 14 +++--- .../download-dialog/DownloadDialog.tsx | 44 +++++++++++++------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/apps/admin-ui/src/clients/ClientDetails.tsx b/apps/admin-ui/src/clients/ClientDetails.tsx index e853cc16fc..f004cd02d7 100644 --- a/apps/admin-ui/src/clients/ClientDetails.tsx +++ b/apps/admin-ui/src/clients/ClientDetails.tsx @@ -386,12 +386,14 @@ export default function ClientDetails() { - + {downloadDialogOpen && ( + + )} { const { adminClient } = useAdminClient(); + const { realm } = useRealm(); const { t } = useTranslation("common"); const { enabled } = useHelp(); const serverInfo = useServerInfo(); @@ -43,7 +46,7 @@ export const DownloadDialog = ({ const [selected, setSelected] = useState( configFormats[configFormats.length - 1].id ); - const [snippet, setSnippet] = useState(""); + const [snippet, setSnippet] = useState(); const [openType, setOpenType] = useState(false); const selectedConfig = useMemo( @@ -59,14 +62,30 @@ export const DownloadDialog = ({ useFetch( async () => { - const snippet = await adminClient.clients.getInstallationProviders({ - id, - providerId: selected, - }); - if (typeof snippet === "string") { - return sanitizeSnippet(snippet); + if (selectedConfig?.mediaType === "application/zip") { + const response = await fetch( + `${addTrailingSlash( + adminClient.baseUrl + )}admin/realms/${realm}/clients/${id}/installation/providers/${selected}`, + { + method: "GET", + headers: getAuthorizationHeaders( + await adminClient.getAccessToken() + ), + } + ); + + return response.arrayBuffer(); } else { - return prettyPrintJSON(snippet); + const snippet = await adminClient.clients.getInstallationProviders({ + id, + providerId: selected, + }); + if (typeof snippet === "string") { + return sanitizeSnippet(snippet); + } else { + return prettyPrintJSON(snippet); + } } }, (snippet) => setSnippet(snippet), @@ -81,10 +100,9 @@ export const DownloadDialog = ({ titleKey={t("clients:downloadAdaptorTitle")} continueButtonLabel={t("download")} onConfirm={() => { - const config = configFormats.find((config) => config.id === selected)!; FileSaver.saveAs( - new Blob([snippet], { type: config.mediaType }), - config.filename + new Blob([snippet!], { type: selectedConfig?.mediaType }), + selectedConfig?.filename ); }} open={open} @@ -163,7 +181,7 @@ export const DownloadDialog = ({ readOnly rows={12} resizeOrientation="vertical" - value={snippet} + value={snippet && typeof snippet === "string" ? snippet : ""} aria-label="text area example" />