feat(elixir): QR code generate & download function

This commit is contained in:
Schuwi
2025-09-14 16:35:06 +02:00
parent 1b498d286d
commit 788ad54724
10 changed files with 290 additions and 46 deletions

View File

@@ -40,6 +40,32 @@ window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
// connect if there are any LiveViews on the page
liveSocket.connect()
// Add file download functionality
window.addEventListener("phx:download_file", (event) => {
const { filename, data, mime_type } = event.detail
// Convert base64 to blob
const byteCharacters = atob(data)
const byteNumbers = new Array(byteCharacters.length)
for (let i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
const blob = new Blob([byteArray], { type: mime_type })
// Create download link
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
// Clean up
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
})
// expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session