feat: Implement native file sharing with Web Share API, falling back to individual downloads.
This commit is contained in:
@@ -662,18 +662,30 @@ const downloadSelected = async () => {
|
||||
const projectId = localStorage.getItem('active_project_id')
|
||||
if (projectId) headers['X-Project-ID'] = projectId
|
||||
|
||||
// Fetch all blobs
|
||||
const files = []
|
||||
for (const assetId of ids) {
|
||||
const url = API_URL + '/assets/' + assetId
|
||||
const resp = await fetch(url, { headers })
|
||||
const blob = await resp.blob()
|
||||
files.push(new File([blob], assetId + '.png', { type: blob.type || 'image/png' }))
|
||||
}
|
||||
|
||||
// Try native share (iOS share sheet)
|
||||
if (navigator.canShare && navigator.canShare({ files })) {
|
||||
await navigator.share({ files })
|
||||
} else {
|
||||
// Fallback: browser download
|
||||
for (const file of files) {
|
||||
const a = document.createElement('a')
|
||||
a.href = URL.createObjectURL(blob)
|
||||
a.download = assetId + '.png'
|
||||
a.href = URL.createObjectURL(file)
|
||||
a.download = file.name
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(a.href)
|
||||
}
|
||||
}
|
||||
toast.add({ severity: 'success', summary: 'Downloaded', detail: `${ids.length} image(s) saved`, life: 2000 })
|
||||
} catch (e) {
|
||||
console.error('Download failed', e)
|
||||
|
||||
Reference in New Issue
Block a user