Skip to content

Commit

Permalink
feat: added mwan composable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Sep 25, 2023
1 parent f2618ab commit 1ee3b15
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/composables/useMwan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { onMounted, ref } from 'vue'
import { ubusCall } from '@/lib/standalone/ubus'
import type { AxiosResponse } from 'axios'

export interface Member {
name: string
interface: string
metric: number
weight: number
status: string
}

export interface Policy {
name: string
label?: string
type: 'balance' | 'backup' | 'custom'
members: {
[metric: string]: Array<Member>
}
}

interface ApiResponse {
values: Array<Policy>
}

export function useMwan() {
const loading = ref(true)
const policies = ref<Policy[]>([])
const error = ref<Error>()

async function fetch() {
return await ubusCall('ns.mwan', 'index_policies')
.then((response: AxiosResponse<ApiResponse>) => (policies.value = response.data.values))
.catch((reason: Error) => (error.value = reason))
}

onMounted(() => {
fetch().finally(() => (loading.value = false))
})

return { loading, fetch, policies, error }
}

0 comments on commit 1ee3b15

Please sign in to comment.