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() {
|
public mounted() {
|
||||||
this.$advent22
|
this.$advent22
|
||||||
.api_get_string("days/date")
|
.api_get<string>("days/date")
|
||||||
.then((date: string) => (this.date = date));
|
.then((date: string) => (this.date = date));
|
||||||
|
|
||||||
this.$advent22
|
this.$advent22
|
||||||
.api_get_number("days/visible_days")
|
.api_get<number>("days/visible_days")
|
||||||
.then((visible_days: number) => (this.visible_days = visible_days));
|
.then((visible_days: number) => (this.visible_days = visible_days));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,9 +51,7 @@ export default class extends Vue {
|
||||||
public doors: Door[] = [];
|
public doors: Door[] = [];
|
||||||
|
|
||||||
public load_doors() {
|
public load_doors() {
|
||||||
this.$advent22
|
this.$advent22.api_get<DoorSerialized[]>("/general/doors").then((data) => {
|
||||||
.api_get_json<DoorSerialized[]>("/general/doors")
|
|
||||||
.then((data) => {
|
|
||||||
this.doors.length = 0;
|
this.doors.length = 0;
|
||||||
|
|
||||||
for (const value of data) {
|
for (const value of data) {
|
||||||
|
|
|
@ -42,9 +42,9 @@ export class Advent22 {
|
||||||
this.api_auth = { username: username, password: password };
|
this.api_auth = { username: username, password: password };
|
||||||
}
|
}
|
||||||
|
|
||||||
private api_get<T>(endpoint: string): Promise<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): Promise<T>;
|
||||||
private api_get<T>(
|
private _api_get<T>(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
responseType: ResponseType = "json",
|
responseType: ResponseType = "json",
|
||||||
): Promise<T> {
|
): 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> {
|
public api_get_blob(endpoint: string): Promise<string> {
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
this.api_get<Blob>(endpoint, "blob")
|
this._api_get<Blob>(endpoint, "blob")
|
||||||
.then((data: Blob) => {
|
.then((data: Blob) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(data);
|
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> {
|
public api_put(endpoint: string, data: unknown): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) =>
|
return new Promise<void>((resolve, reject) =>
|
||||||
this.axios
|
this.axios
|
||||||
|
|
Loading…
Reference in a new issue