(imageUrl, filename)
| 96 | }, 100); |
| 97 | }); |
| 98 | async function downloadByFetch(imageUrl, filename) { |
| 99 | try { |
| 100 | const response = await fetch(imageUrl); |
| 101 | if (!response.ok) throw new Error('CORS request failed'); |
| 102 | const blob = await response.blob(); |
| 103 | const blobUrl = URL.createObjectURL(blob); |
| 104 | const tempLink = document.createElement('a'); |
| 105 | tempLink.href = blobUrl; |
| 106 | tempLink.setAttribute('download', filename); |
| 107 | document.body.appendChild(tempLink); |
| 108 | tempLink.click(); |
| 109 | document.body.removeChild(tempLink); |
| 110 | URL.revokeObjectURL(blobUrl); |
| 111 | } catch (error) { |
| 112 | console.error('error:', error); |
| 113 | window.open(imageUrl, '_blank'); |
| 114 | } |
| 115 | } |
| 116 | const show = (ele) => { |
| 117 | ele.appendChild(downloadBtn); |
| 118 | setTimeout(() => { |
no test coverage detected