diff --git a/src/lib/components/FileManagement/DownloadButtons.svelte b/src/lib/components/FileManagement/DownloadButtons.svelte index 98ef2c5..3a33553 100644 --- a/src/lib/components/FileManagement/DownloadButtons.svelte +++ b/src/lib/components/FileManagement/DownloadButtons.svelte @@ -4,63 +4,51 @@ import { stringify } from 'yaml'; $: fileName = filenamify($openApiStore?.info?.title) || 'openapi'; + + // TODO: Refactor this to use the new storage instead of localstorage + const saveYAML = () => { + const openApiStorage = localStorage.getItem(`${localStoragePrefix}openApi`); + if (!openApiStorage) return; + const openApi = JSON.parse(openApiStorage); + const blob = new Blob([stringify(openApi, null, { indent: 2, aliasDuplicateObjects: false })], { + type: 'application/yaml' + }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `${fileName}.yaml`; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }; + + // TODO: Refactor this to use the new storage instead of localstorage + const saveJSON = () => { + const openApiStorage = localStorage.getItem(`${localStoragePrefix}openApi`); + if (!openApiStorage) return; + const openApi = JSON.parse(openApiStorage); + const blob = new Blob([JSON.stringify(openApi, null, 2)], { + type: 'application/json' + }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `${fileName}.json`; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }; -