21 lines
517 B
TypeScript
21 lines
517 B
TypeScript
export const apiFetch = $fetch.create({})
|
|
|
|
export function apiRequest(input: RequestInfo | URL, init: RequestInit = {}) {
|
|
return fetch(input, withApiAuth(init))
|
|
}
|
|
|
|
export async function downloadApiFile(url: string, fileNameFallback: string) {
|
|
const link = document.createElement("a")
|
|
|
|
link.href = url
|
|
link.download = fileNameFallback
|
|
link.style.display = "none"
|
|
document.body.appendChild(link)
|
|
link.click()
|
|
link.remove()
|
|
}
|
|
|
|
export function withApiAuth(init: RequestInit = {}) {
|
|
return { ...init }
|
|
}
|