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