(fileId, fileName = null)
| 115 | }; |
| 116 | |
| 117 | export const downloadFile = (fileId, fileName = null) => { |
| 118 | // const authToken = localStorage.getItem('accessToken'); |
| 119 | const authToken = Cookies.get("accessToken"); |
| 120 | const url = `${baseUrl()}/resources/get/${fileId}`; |
| 121 | const env = localStorage.getItem('applicationEnvironment'); |
| 122 | |
| 123 | if (env === 'PROD') { |
| 124 | const headers = { |
| 125 | Authorization: `Bearer ${authToken}`, |
| 126 | }; |
| 127 | |
| 128 | return fetch(url, {headers}) |
| 129 | .then((response) => response.blob()) |
| 130 | .then((blob) => { |
| 131 | if (fileName) { |
| 132 | const fileUrl = window.URL.createObjectURL(blob); |
| 133 | const anchorElement = document.createElement('a'); |
| 134 | anchorElement.href = fileUrl; |
| 135 | anchorElement.download = fileName; |
| 136 | anchorElement.click(); |
| 137 | window.URL.revokeObjectURL(fileUrl); |
| 138 | } else { |
| 139 | return blob; |
| 140 | } |
| 141 | }) |
| 142 | .catch((error) => { |
| 143 | console.error('Error downloading file:', error); |
| 144 | }); |
| 145 | } else { |
| 146 | if (fileName) { |
| 147 | window.open(url, '_blank'); |
| 148 | } else { |
| 149 | return fetch(url) |
| 150 | .then((response) => response.blob()) |
| 151 | .catch((error) => { |
| 152 | console.error('Error downloading file:', error); |
| 153 | }); |
| 154 | } |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | export const downloadAllFiles = (files, run_name) => { |
| 159 | const zip = new JSZip(); |
no test coverage detected