Spaces:
Sleeping
Sleeping
File size: 852 Bytes
43370b3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | export type ExportFormat = 'pdf' | 'pptx' | 'html'
/** POST the current markdown to the server, then download the rendered file. */
export async function requestExport(markdown: string, format: ExportFormat): Promise<void> {
const res = await fetch('/api/export', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ markdown, format }),
})
if (!res.ok) {
let message = 'Export failed'
try {
const j = await res.json()
message = j.detail || j.error || message
} catch {
/* ignore */
}
throw new Error(message)
}
const blob = await res.blob()
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `deck.${format}`
document.body.appendChild(a)
a.click()
a.remove()
URL.revokeObjectURL(url)
}
|