Compare commits

..

1 commit

Author SHA1 Message Date
b773a0dde1 Add loading server configs 2023-05-03 20:31:42 +02:00
3 changed files with 2 additions and 43 deletions

View file

@ -1,22 +0,0 @@
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
}

View file

@ -1,19 +0,0 @@
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")
}

View file

@ -1,8 +1,8 @@
<script setup lang="ts">
import TableComponent from '@/components/TableComponent.vue';
const tableHeader = ["ID", "Server ID", "System Message", "Context Length", "Rate limit", "Created"]
const tableRows = [["1", "name", "comment", "5", "1", Date.now()]]
const tableHeader = ["ID", "Server ID", "System Message", "Rate limit"]
const tableRows = [["1", "name", "comment", "1"]]
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>
<template>