Simple API query wrappers
This commit is contained in:
parent
fc9a51da5d
commit
5ffc886298
1 changed files with 39 additions and 9 deletions
|
@ -83,20 +83,50 @@ export default class App extends Vue {
|
|||
private ticker_html = "<p>changeme</p>";
|
||||
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<string, string>) => void
|
||||
): void {
|
||||
this.api_query_simple(endpoint, (data) => {
|
||||
if (typeof data !== "object") return;
|
||||
if (data === null) return;
|
||||
|
||||
on_success(data as Record<string, string>);
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue