Implement apstatus fetch on svelte site + protobuf decode
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -71,13 +71,6 @@ export type NetworkItem = {
|
||||
encryption_type: number
|
||||
}
|
||||
|
||||
export type ApStatus = {
|
||||
status: number
|
||||
ip_address: number
|
||||
mac_address: string
|
||||
station_num: number
|
||||
}
|
||||
|
||||
export type ApSettings = {
|
||||
provision_mode: number
|
||||
ssid: string
|
||||
|
||||
Reference in New Issue
Block a user