Ap settngs post working, error msg on response

This commit is contained in:
Niklas Jensen
2026-01-24 11:24:09 +01:00
committed by nikguin04
parent ae4a2fe115
commit d5af8d0294
6 changed files with 39 additions and 33 deletions
+12 -3
View File
@@ -2,7 +2,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'
import { Request, Response } from './platform_shared/api'
import { BinaryWriter } from '@bufbuild/protobuf/wire'
export const api = {
get<TResponse>(endpoint: string, params?: RequestInit) {
@@ -13,6 +14,10 @@ export const api = {
return sendRequest<TResponse>(endpoint, 'POST', data)
},
post_proto<TResponse>(endpoint: string, data: Request) {
return sendRequest<TResponse>(endpoint, 'POST', Request.encode(data))
},
put<TResponse>(endpoint: string, data?: unknown) {
return sendRequest<TResponse>(endpoint, 'PUT', data)
},
@@ -29,7 +34,11 @@ async function sendRequest<TResponse>(
params?: RequestInit
): Promise<Result<TResponse, Error>> {
endpoint = resolveUrl(endpoint)
const body = data !== null && typeof data !== 'undefined' ? JSON.stringify(data) : undefined
const isProtobuf = data instanceof BinaryWriter
const body = data !== null && typeof data !== 'undefined'
? (isProtobuf ? data.finish() : JSON.stringify(data))
: undefined
const request = {
...params,
@@ -38,7 +47,7 @@ async function sendRequest<TResponse>(
headers: {
...params?.headers,
Authorization: 'Basic',
'Content-Type': 'application/json'
'Content-Type': isProtobuf ? 'application/x-protobuf' : 'application/json'
}
}
-12
View File
@@ -71,18 +71,6 @@ export type NetworkItem = {
encryption_type: number
}
export type ApSettings = {
provision_mode: number
ssid: string
password: string
channel: number
ssid_hidden: boolean
max_clients: number
local_ip: number
gateway_ip: number
subnet_mask: number
}
export type Rssi = {
rssi: number
ssid: string