feat: Implement native file sharing with Web Share API, falling back to individual downloads.

This commit is contained in:
xds
2026-02-16 17:46:35 +03:00
parent fc9048fc94
commit 6bda0db181

View File

@@ -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)