From a9754f77bc877445e8c9f2080751f01fd5829c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 7 Sep 2023 17:00:28 +0000 Subject: [PATCH] use Advent22 api_get --- ui/src/App.vue | 4 ++-- ui/src/components/DoorMapEditor.vue | 14 ++++++-------- ui/src/plugins/advent22.ts | 24 ++++++++---------------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index b6bc201..669a140 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -41,11 +41,11 @@ export default class extends Vue { public mounted() { this.$advent22 - .api_get_string("days/date") + .api_get("days/date") .then((date: string) => (this.date = date)); this.$advent22 - .api_get_number("days/visible_days") + .api_get("days/visible_days") .then((visible_days: number) => (this.visible_days = visible_days)); } } diff --git a/ui/src/components/DoorMapEditor.vue b/ui/src/components/DoorMapEditor.vue index 35dd6cf..14012ea 100644 --- a/ui/src/components/DoorMapEditor.vue +++ b/ui/src/components/DoorMapEditor.vue @@ -51,15 +51,13 @@ export default class extends Vue { public doors: Door[] = []; public load_doors() { - this.$advent22 - .api_get_json("/general/doors") - .then((data) => { - this.doors.length = 0; + this.$advent22.api_get("/general/doors").then((data) => { + this.doors.length = 0; - for (const value of data) { - this.doors.push(Door.deserialize(value)); - } - }); + for (const value of data) { + this.doors.push(Door.deserialize(value)); + } + }); } public save_doors() { diff --git a/ui/src/plugins/advent22.ts b/ui/src/plugins/advent22.ts index 9b23b13..72db94a 100644 --- a/ui/src/plugins/advent22.ts +++ b/ui/src/plugins/advent22.ts @@ -42,9 +42,9 @@ export class Advent22 { this.api_auth = { username: username, password: password }; } - private api_get(endpoint: string): Promise; - private api_get(endpoint: string, responseType: ResponseType): Promise; - private api_get( + private _api_get(endpoint: string): Promise; + private _api_get(endpoint: string, responseType: ResponseType): Promise; + private _api_get( endpoint: string, responseType: ResponseType = "json", ): Promise { @@ -64,9 +64,13 @@ export class Advent22 { }); } + public api_get(endpoint: string): Promise { + return this._api_get(endpoint); + } + public api_get_blob(endpoint: string): Promise { return new Promise((resolve, reject) => { - this.api_get(endpoint, "blob") + this._api_get(endpoint, "blob") .then((data: Blob) => { const reader = new FileReader(); reader.readAsDataURL(data); @@ -82,18 +86,6 @@ export class Advent22 { }); } - public api_get_string(endpoint: string): Promise { - return this.api_get(endpoint); - } - - public api_get_number(endpoint: string): Promise { - return this.api_get(endpoint); - } - - public api_get_json(endpoint: string): Promise { - return this.api_get(endpoint); - } - public api_put(endpoint: string, data: unknown): Promise { return new Promise((resolve, reject) => this.axios