mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 14:37:21 +01:00
32 lines
835 B
TypeScript
32 lines
835 B
TypeScript
function checkStatus(res: Response) {
|
|
if (res.status < 200 || res.status >= 400) {
|
|
throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`)
|
|
}
|
|
}
|
|
|
|
export async function generatePdf(state: Record<string, string>) {
|
|
const options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(state),
|
|
}
|
|
|
|
const response = await fetch('/api/pdf/generate/brief', options)
|
|
checkStatus(response)
|
|
return response.json()
|
|
}
|
|
|
|
export async function getLatest() {
|
|
const response = await fetch('/api/pdf/latest')
|
|
checkStatus(response)
|
|
return response.json()
|
|
}
|
|
|
|
export async function removeLatest(item: { id: string }) {
|
|
const response = await fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' })
|
|
checkStatus(response)
|
|
return response
|
|
}
|