Compare commits
2 commits
b773a0dde1
...
44c6a3b1a7
Author | SHA1 | Date | |
---|---|---|---|
44c6a3b1a7 | |||
cf42778103 |
3 changed files with 43 additions and 2 deletions
22
ui/src/models/server.ts
Normal file
22
ui/src/models/server.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
export type ServerConfig = {
|
||||||
|
id: number,
|
||||||
|
serverId: number,
|
||||||
|
systemMessage: string,
|
||||||
|
rateLimit: number,
|
||||||
|
time: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const exampleServerConfig: ServerConfig = {
|
||||||
|
id: 1,
|
||||||
|
serverId: 1091358909513609246,
|
||||||
|
systemMessage: "Foo",
|
||||||
|
rateLimit: 10,
|
||||||
|
time: "1680676051.633872000"
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isServerConfig(serverConfig: ServerConfig | any): serverConfig is ServerConfig {
|
||||||
|
const requiredFields = Object.getOwnPropertyNames(exampleServerConfig)
|
||||||
|
const fieldsToCheck = Object.getOwnPropertyNames(serverConfig)
|
||||||
|
const foundFields = requiredFields.filter(field => fieldsToCheck.filter(fieldToCheck => fieldToCheck === field).length === 1)
|
||||||
|
return foundFields.length >= requiredFields.length
|
||||||
|
}
|
19
ui/src/services/ServerConfigs.ts
Normal file
19
ui/src/services/ServerConfigs.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { isServerConfig, type ServerConfig } from "@/models/server";
|
||||||
|
|
||||||
|
export async function getConfigs(): Promise<ServerConfig[]> {
|
||||||
|
return fetch(import.meta.env.VITE_API_URL + "/servers/configs")
|
||||||
|
.then(shouldBeSuccess)
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(toArray)
|
||||||
|
.then(list => list.filter(isServerConfig))
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldBeSuccess(res: Response): Response {
|
||||||
|
if (res.status >= 200 && res.status < 300) return res
|
||||||
|
throw new Error(`Expected success status code but got: ${res.status} ${res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toArray(subject: any): any[] {
|
||||||
|
if (subject instanceof Array) return subject as any[]
|
||||||
|
throw new Error("Could not be casted to an array")
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import TableComponent from '@/components/TableComponent.vue';
|
import TableComponent from '@/components/TableComponent.vue';
|
||||||
|
|
||||||
const tableHeader = ["ID", "Server ID", "System Message", "Rate limit"]
|
const tableHeader = ["ID", "Server ID", "System Message", "Context Length", "Rate limit", "Created"]
|
||||||
const tableRows = [["1", "name", "comment", "1"]]
|
const tableRows = [["1", "name", "comment", "5", "1", Date.now()]]
|
||||||
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
const actions = [{ class: "btn btn-sm btn-info m-1", content: "Edit", event: (_: number) => { } }, { class: "btn btn-sm btn-error m-1", content: "Delete", event: (_: number) => { } }]
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in a new issue