(files, run_name)
| 156 | }; |
| 157 | |
| 158 | export const downloadAllFiles = (files, run_name) => { |
| 159 | const zip = new JSZip(); |
| 160 | const promises = []; |
| 161 | const fileNamesCount = {}; |
| 162 | |
| 163 | files.forEach((file, index) => { |
| 164 | fileNamesCount[file.name] |
| 165 | ? fileNamesCount[file.name]++ |
| 166 | : (fileNamesCount[file.name] = 1); |
| 167 | |
| 168 | let modifiedFileName = file.name; |
| 169 | if (fileNamesCount[file.name] > 1) { |
| 170 | const fileExtensionIndex = file.name.lastIndexOf("."); |
| 171 | const name = file.name.substring(0, fileExtensionIndex); |
| 172 | const extension = file.name.substring(fileExtensionIndex + 1); |
| 173 | modifiedFileName = `${name} (${fileNamesCount[file.name] - 1}).${extension}`; |
| 174 | } |
| 175 | |
| 176 | const promise = downloadFile(file.id) |
| 177 | .then((blob) => { |
| 178 | const fileBlob = new Blob([blob], {type: file.type}); |
| 179 | zip.file(modifiedFileName, fileBlob); |
| 180 | }) |
| 181 | .catch((error) => { |
| 182 | console.error("Error downloading file:", error); |
| 183 | }); |
| 184 | |
| 185 | promises.push(promise); |
| 186 | }); |
| 187 | |
| 188 | Promise.all(promises) |
| 189 | .then(() => { |
| 190 | zip.generateAsync({type: "blob"}) |
| 191 | .then((content) => { |
| 192 | const now = new Date(); |
| 193 | const timestamp = `${now.getFullYear()}-${("0" + (now.getMonth() + 1)).slice(-2)}-${("0" + now.getDate()).slice(-2)}_${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`.replace(/:/g, '-'); |
| 194 | const zipFilename = `${run_name}_${timestamp}.zip`; |
| 195 | const downloadLink = document.createElement("a"); |
| 196 | downloadLink.href = URL.createObjectURL(content); |
| 197 | downloadLink.download = zipFilename; |
| 198 | downloadLink.click(); |
| 199 | }) |
| 200 | .catch((error) => { |
| 201 | console.error("Error generating zip:", error); |
| 202 | }); |
| 203 | }); |
| 204 | }; |
| 205 | |
| 206 | export const refreshUrl = () => { |
| 207 | if (typeof window === 'undefined') { |
no test coverage detected