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()
})
}
+17 -10
View File
@@ -90,20 +90,27 @@ export default {
this.isDownloading = true
fetch(`/submitters/${this.submitterSlug}/download`).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.isDownloading = false
})
}
+2 -2
View File
@@ -191,7 +191,7 @@
:field="currentField"
:attachments-index="attachmentsIndex"
:submitter-slug="submitterSlug"
@attached="attachments.push($event)"
@attached="[attachments.push($event), $refs.areas.scrollIntoField(currentField)]"
/>
<SignatureStep
v-else-if="currentField.type === 'signature'"
@@ -208,7 +208,7 @@
:field="currentField"
:attachments-index="attachmentsIndex"
:submitter-slug="submitterSlug"
@attached="attachments.push($event)"
@attached="[attachments.push($event), $refs.areas.scrollIntoField(currentField)]"
/>
</div>
<div class="mt-8">