Implement apstatus fetch on svelte site + protobuf decode
This commit is contained in:
@@ -17,7 +17,7 @@ const pluginPath =
|
|||||||
path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto.cmd')
|
path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto.cmd')
|
||||||
: path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto')
|
: path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto')
|
||||||
|
|
||||||
const protoFiles = ['filesystem.proto', 'message.proto']
|
const protoFiles = ['filesystem.proto', 'message.proto', "api.proto"]
|
||||||
|
|
||||||
const tsProtoOpts = ['useExactTypes=false', 'outputExtensions=true', 'outputSchema=true'].join(',')
|
const tsProtoOpts = ['useExactTypes=false', 'outputExtensions=true', 'outputSchema=true'].join(',')
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import { Err, Ok, type Result } from './utilities'
|
import { Err, Ok, type Result } from './utilities'
|
||||||
import { apiLocation } from './stores/location-store'
|
import { apiLocation } from './stores/location-store'
|
||||||
|
import type { MessageFns } from './platform_shared/filesystem'
|
||||||
|
import { Response } from './platform_shared/api'
|
||||||
|
|
||||||
export const api = {
|
export const api = {
|
||||||
get<TResponse>(endpoint: string, params?: RequestInit) {
|
get<TResponse>(endpoint: string, params?: RequestInit) {
|
||||||
@@ -60,6 +62,9 @@ async function sendRequest<TResponse>(
|
|||||||
if (contentType && contentType.includes('application/json')) {
|
if (contentType && contentType.includes('application/json')) {
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
return Ok.new(data as TResponse)
|
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 {
|
} else {
|
||||||
// Handle empty object as response
|
// Handle empty object as response
|
||||||
return Ok.new(null as TResponse)
|
return Ok.new(null as TResponse)
|
||||||
|
|||||||
@@ -71,13 +71,6 @@ export type NetworkItem = {
|
|||||||
encryption_type: number
|
encryption_type: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApStatus = {
|
|
||||||
status: number
|
|
||||||
ip_address: number
|
|
||||||
mac_address: string
|
|
||||||
station_num: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ApSettings = {
|
export type ApSettings = {
|
||||||
provision_mode: number
|
provision_mode: number
|
||||||
ssid: string
|
ssid: string
|
||||||
|
|||||||
@@ -6,14 +6,16 @@
|
|||||||
import SettingsCard from '$lib/components/SettingsCard.svelte'
|
import SettingsCard from '$lib/components/SettingsCard.svelte'
|
||||||
import { notifications } from '$lib/components/toasts/notifications'
|
import { notifications } from '$lib/components/toasts/notifications'
|
||||||
import Spinner from '$lib/components/Spinner.svelte'
|
import Spinner from '$lib/components/Spinner.svelte'
|
||||||
import type { ApSettings, ApStatus } from '$lib/types/models'
|
import { type ApSettings } from '$lib/types/models'
|
||||||
import { api } from '$lib/api'
|
import { api } from '$lib/api'
|
||||||
import { ipToUint32, uint32ToIp, isValidIpString } from '$lib/utilities'
|
import { ipToUint32, uint32ToIp, isValidIpString } from '$lib/utilities'
|
||||||
import { AP, Devices, Home, MAC } from '$lib/components/icons'
|
import { AP, Devices, Home, MAC } from '$lib/components/icons'
|
||||||
import StatusItem from '$lib/components/StatusItem.svelte'
|
import StatusItem from '$lib/components/StatusItem.svelte'
|
||||||
|
import { APStatus, Response } from '$lib/platform_shared/api'
|
||||||
|
import { input } from '$lib/stores'
|
||||||
|
|
||||||
let apSettings: ApSettings | null = $state(null)
|
let apSettings: ApSettings | null = $state(null)
|
||||||
let apStatus: ApStatus | null = $state(null)
|
let apStatus: APStatus | null = $state(null)
|
||||||
|
|
||||||
let ipDisplay = $state({
|
let ipDisplay = $state({
|
||||||
local_ip: '',
|
local_ip: '',
|
||||||
@@ -24,13 +26,13 @@
|
|||||||
let formField: Record<string, unknown> = $state({})
|
let formField: Record<string, unknown> = $state({})
|
||||||
|
|
||||||
async function getAPStatus() {
|
async function getAPStatus() {
|
||||||
const result = await api.get<ApStatus>('/api/ap/status')
|
const result = await api.get<Response>('/api/ap/status')
|
||||||
if (result.isErr()) {
|
if (result.isErr()) {
|
||||||
console.error('Error:', result.inner)
|
console.error('Error:', result.inner)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
apStatus = result.inner
|
|
||||||
return apStatus
|
apStatus = result.inner.apStatus!
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAPSettings() {
|
async function getAPSettings() {
|
||||||
@@ -181,15 +183,15 @@
|
|||||||
<StatusItem
|
<StatusItem
|
||||||
icon={Home}
|
icon={Home}
|
||||||
title="IP Address"
|
title="IP Address"
|
||||||
description={uint32ToIp(apStatus.ip_address)}
|
description={uint32ToIp(apStatus.ipAddress)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<StatusItem icon={MAC} title="MAC Address" description={apStatus.mac_address} />
|
<StatusItem icon={MAC} title="MAC Address" description={apStatus.macAddress} />
|
||||||
|
|
||||||
<StatusItem
|
<StatusItem
|
||||||
icon={Devices}
|
icon={Devices}
|
||||||
title="AP Clients"
|
title="AP Clients"
|
||||||
description={apStatus.station_num}
|
description={apStatus.stationNum}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user