diff --git a/ui/src/App.vue b/ui/src/App.vue index 9435e9a..a73d92e 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -83,20 +83,50 @@ export default class App extends Vue { private ticker_html = "

changeme

"; private ticker_color = "primary"; - private fail(part: string): (arg0: unknown) => void { + private fail(name: string): (arg0: unknown) => void { return (reason: unknown) => - console.warn("Failed to update", part, "-", reason); + console.warn("Failed to query", name, "-", reason); + } + + private api_query_simple( + endpoint: string, + on_success: (data: unknown) => void + ): void { + this.$axios + .get(this.$ovdashboard.api_url(endpoint)) + .then((response) => on_success(response.data)) + .catch(this.fail(endpoint)); + } + + private api_query_simple_string( + endpoint: string, + on_success: (data: string) => void + ): void { + this.api_query_simple(endpoint, (data) => { + if (typeof data !== "string") return; + + on_success(data); + }); + } + + private api_query_simple_object( + endpoint: string, + on_success: (data: Record) => void + ): void { + this.api_query_simple(endpoint, (data) => { + if (typeof data !== "object") return; + if (data === null) return; + + on_success(data as Record); + }); } private update(): void { // Update Logo Config - this.$axios - .get(this.$ovdashboard.api_url("misc/config/logo")) - .then((response) => { - this.logo_above = response.data.above; - this.logo_below = response.data.below; - }) - .catch(this.fail("Logo Config")); + this.api_query_simple_object("misc/config/logo", (data) => { + this.logo_above = data.above; + this.logo_below = data.below; + }); // Update Title this.$axios