From 9150fecd697d384e1d11061692f7623d544f629d Mon Sep 17 00:00:00 2001 From: Fabricio Date: Thu, 7 Nov 2024 15:35:01 +0100 Subject: [PATCH] download filename fix --- assets/vue/controllers/Page/CustomizerPage.vue | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/assets/vue/controllers/Page/CustomizerPage.vue b/assets/vue/controllers/Page/CustomizerPage.vue index 6f3d438..f15b84a 100644 --- a/assets/vue/controllers/Page/CustomizerPage.vue +++ b/assets/vue/controllers/Page/CustomizerPage.vue @@ -182,13 +182,19 @@ export default { ); const url = window.URL.createObjectURL(new Blob([response.data])); + + let filename = ''; + const contentDisposition = response.headers['content-disposition']; + if (contentDisposition) { + const filenameMatch = contentDisposition.match(/filename="(.+)"/); + if (filenameMatch.length > 1) { + filename = filenameMatch[1]; + } + } + const link = document.createElement('a'); link.href = url; - if (identifier === 'variables') { - link.setAttribute('download', `${identifier}.scss`); - } else { - link.setAttribute('download', `${identifier}.css`); - } + link.setAttribute('download', filename); document.body.appendChild(link); link.click(); link.remove();