generate pdfs from images

This commit is contained in:
Alex Turchyn
2023-06-22 01:31:39 +03:00
parent 1da67011c4
commit 92e05ae8e9
5 changed files with 127 additions and 43 deletions
+17 -10
View File
@@ -18,20 +18,27 @@ export default targetable(class extends HTMLElement {
this.toggleState()
fetch(this.dataset.src).then((response) => response.json()).then((urls) => {
urls.forEach((url) => {
fetch(url).then(async (resp) => {
const blobUrl = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
const fileRequests = urls.map((url) => {
return () => {
return fetch(url).then(async (resp) => {
const blobUrl = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
link.href = blobUrl
link.setAttribute('download', resp.headers.get('content-disposition').split('"')[1])
link.href = blobUrl
link.setAttribute('download', decodeURI(resp.headers.get('content-disposition').split('"')[1]))
link.click()
link.click()
URL.revokeObjectURL(url)
})
URL.revokeObjectURL(url)
})
}
})
}).finally(() => {
fileRequests.reduce(
(prevPromise, request) => prevPromise.then(() => request()),
Promise.resolve()
)
this.toggleState()
})
}