Implement apstatus fetch on svelte site + protobuf decode

This commit is contained in:
Niklas Jensen
2026-01-23 15:27:44 +01:00
committed by nikguin04
parent e1e656478d
commit ae4a2fe115
4 changed files with 16 additions and 16 deletions
+5
View File
@@ -1,6 +1,8 @@
import { get } from 'svelte/store'
import { Err, Ok, type Result } from './utilities'
import { apiLocation } from './stores/location-store'
import type { MessageFns } from './platform_shared/filesystem'
import { Response } from './platform_shared/api'
export const api = {
get<TResponse>(endpoint: string, params?: RequestInit) {
@@ -60,6 +62,9 @@ async function sendRequest<TResponse>(
if (contentType && contentType.includes('application/json')) {
const data = await response.json()
return Ok.new(data as TResponse)
} else if (contentType && contentType.includes('application/x-protobuf')) {
let data: Response = Response.decode(await response.bytes());
return Ok.new(data as TResponse)
} else {
// Handle empty object as response
return Ok.new(null as TResponse)