use Advent22 api_get<T>
This commit is contained in:
parent
27db0ea908
commit
a9754f77bc
3 changed files with 16 additions and 26 deletions
|
@ -41,11 +41,11 @@ export default class extends Vue {
|
|||
|
||||
public mounted() {
|
||||
this.$advent22
|
||||
.api_get_string("days/date")
|
||||
.api_get<string>("days/date")
|
||||
.then((date: string) => (this.date = date));
|
||||
|
||||
this.$advent22
|
||||
.api_get_number("days/visible_days")
|
||||
.api_get<number>("days/visible_days")
|
||||
.then((visible_days: number) => (this.visible_days = visible_days));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,15 +51,13 @@ export default class extends Vue {
|
|||
public doors: Door[] = [];
|
||||
|
||||
public load_doors() {
|
||||
this.$advent22
|
||||
.api_get_json<DoorSerialized[]>("/general/doors")
|
||||
.then((data) => {
|
||||
this.doors.length = 0;
|
||||
this.$advent22.api_get<DoorSerialized[]>("/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() {
|
||||
|
|
|
@ -42,9 +42,9 @@ export class Advent22 {
|
|||
this.api_auth = { username: username, password: password };
|
||||
}
|
||||
|
||||
private api_get<T>(endpoint: string): Promise<T>;
|
||||
private api_get<T>(endpoint: string, responseType: ResponseType): Promise<T>;
|
||||
private api_get<T>(
|
||||
private _api_get<T>(endpoint: string): Promise<T>;
|
||||
private _api_get<T>(endpoint: string, responseType: ResponseType): Promise<T>;
|
||||
private _api_get<T>(
|
||||
endpoint: string,
|
||||
responseType: ResponseType = "json",
|
||||
): Promise<T> {
|
||||
|
@ -64,9 +64,13 @@ export class Advent22 {
|
|||
});
|
||||
}
|
||||
|
||||
public api_get<T>(endpoint: string): Promise<T> {
|
||||
return this._api_get<T>(endpoint);
|
||||
}
|
||||
|
||||
public api_get_blob(endpoint: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
this.api_get<Blob>(endpoint, "blob")
|
||||
this._api_get<Blob>(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<string> {
|
||||
return this.api_get<string>(endpoint);
|
||||
}
|
||||
|
||||
public api_get_number(endpoint: string): Promise<number> {
|
||||
return this.api_get<number>(endpoint);
|
||||
}
|
||||
|
||||
public api_get_json<T>(endpoint: string): Promise<T> {
|
||||
return this.api_get<T>(endpoint);
|
||||
}
|
||||
|
||||
public api_put(endpoint: string, data: unknown): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) =>
|
||||
this.axios
|
||||
|
|
Loading…
Reference in a new issue