From df05cf23454c3ce1635d44087bb414923d2a1fb5 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 25 Mar 2024 10:24:20 +0100 Subject: [PATCH] Lint --- packages/frontend-core/src/utils/download.js | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/frontend-core/src/utils/download.js b/packages/frontend-core/src/utils/download.js index b887122969..55ba899ee6 100644 --- a/packages/frontend-core/src/utils/download.js +++ b/packages/frontend-core/src/utils/download.js @@ -46,23 +46,23 @@ export async function downloadFile(url, body) { if (!response.ok) { return false + } else { + const contentDisposition = response.headers.get("Content-Disposition") + + const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( + contentDisposition + ) + + const filename = matches[1].replace(/['"]/g, "") + + const url = URL.createObjectURL(await response.blob()) + + const link = document.createElement("a") + link.href = url + link.download = filename + link.click() + + URL.revokeObjectURL(url) + return true } - - const contentDisposition = response.headers.get("Content-Disposition") - - const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec( - contentDisposition - ) - - const filename = matches[1].replace(/['"]/g, "") - - const url = URL.createObjectURL(await response.blob()) - - const link = document.createElement("a") - link.href = url - link.download = filename - link.click() - - URL.revokeObjectURL(url) - return true }