mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-22 15:53:01 +00:00
various cleanup
This commit is contained in:
parent
5e0f797a2f
commit
5fcc4f0684
7 changed files with 59 additions and 59 deletions
|
@ -13,7 +13,7 @@ class User(BaseModel):
|
|||
|
||||
class Puzzle(BaseModel):
|
||||
# Titel
|
||||
# TODO
|
||||
# TODO neue Route GET /user/title
|
||||
title: str
|
||||
|
||||
# Lösungswort
|
||||
|
|
|
@ -80,18 +80,6 @@ async def get_config_model(
|
|||
)
|
||||
|
||||
|
||||
@router.get("/day_parts")
|
||||
async def get_day_parts(
|
||||
_: None = Depends(require_admin),
|
||||
parts: dict[int, str] = Depends(get_all_parts),
|
||||
) -> dict[int, str]:
|
||||
"""
|
||||
Zuordnung der Lösungsteile zu den Tagen
|
||||
"""
|
||||
|
||||
return parts
|
||||
|
||||
|
||||
@router.get("/day_image_names")
|
||||
async def get_day_image_names(
|
||||
_: None = Depends(require_admin),
|
||||
|
@ -104,6 +92,18 @@ async def get_day_image_names(
|
|||
return image_names
|
||||
|
||||
|
||||
@router.get("/day_parts")
|
||||
async def get_day_parts(
|
||||
_: None = Depends(require_admin),
|
||||
parts: dict[int, str] = Depends(get_all_parts),
|
||||
) -> dict[int, str]:
|
||||
"""
|
||||
Zuordnung der Lösungsteile zu den Tagen
|
||||
"""
|
||||
|
||||
return parts
|
||||
|
||||
|
||||
@router.get("/doors")
|
||||
async def get_doors(
|
||||
_: None = Depends(require_admin),
|
||||
|
|
|
@ -26,6 +26,18 @@ async def get_background_image(
|
|||
return await api_return_image(await load_image(f"files/{cal_cfg.background}"))
|
||||
|
||||
|
||||
@router.get("/doors")
|
||||
async def get_doors(
|
||||
cal_cfg: CalendarConfig = Depends(get_calendar_config),
|
||||
visible_days: list[int] = Depends(user_visible_days),
|
||||
) -> DoorsSaved:
|
||||
"""
|
||||
User-sichtbare Türchen lesen
|
||||
"""
|
||||
|
||||
return [door for door in cal_cfg.doors if door.day in visible_days]
|
||||
|
||||
|
||||
@router.get(
|
||||
"/image_{day}",
|
||||
response_class=StreamingResponse,
|
||||
|
@ -50,18 +62,6 @@ async def get_image_for_day(
|
|||
return await api_return_image(image)
|
||||
|
||||
|
||||
@router.get("/doors")
|
||||
async def get_doors(
|
||||
cal_cfg: CalendarConfig = Depends(get_calendar_config),
|
||||
visible_days: list[int] = Depends(user_visible_days),
|
||||
) -> DoorsSaved:
|
||||
"""
|
||||
User-sichtbare Türchen lesen
|
||||
"""
|
||||
|
||||
return [door for door in cal_cfg.doors if door.day in visible_days]
|
||||
|
||||
|
||||
@router.get("/next_door")
|
||||
async def get_next_door(
|
||||
event_dates: EventDates = Depends(get_all_event_dates),
|
||||
|
|
|
@ -38,7 +38,7 @@ export default class extends Vue {
|
|||
public on_click() {
|
||||
if (this.modelValue) {
|
||||
// logout
|
||||
this.$advent22.clear_api_auth();
|
||||
this.$advent22.set_api_auth();
|
||||
this.$emit("update:modelValue", false);
|
||||
} else {
|
||||
// show login modal
|
||||
|
@ -49,7 +49,7 @@ export default class extends Vue {
|
|||
|
||||
public on_submit(username: string, password: string) {
|
||||
this.modal_visible = false;
|
||||
this.$advent22.set_api_auth(username, password);
|
||||
this.$advent22.api_auth = [username, password];
|
||||
|
||||
this.$advent22
|
||||
.api_get<boolean>("admin/is_admin")
|
||||
|
|
|
@ -90,10 +90,10 @@
|
|||
<dd class="is-family-monospace">
|
||||
<BulmaSecret @load="load_dav_credentials">
|
||||
<span class="tag is-danger">user</span>
|
||||
{{ dav_credentials.username }}
|
||||
{{ dav_credentials[0] }}
|
||||
<br />
|
||||
<span class="tag is-danger">pass</span>
|
||||
{{ dav_credentials.password }}
|
||||
{{ dav_credentials[1] }}
|
||||
</BulmaSecret>
|
||||
</dd>
|
||||
|
||||
|
@ -107,10 +107,10 @@
|
|||
<dd class="is-family-monospace">
|
||||
<BulmaSecret @load="load_ui_credentials">
|
||||
<span class="tag is-danger">user</span>
|
||||
{{ ui_credentials.username }}
|
||||
{{ ui_credentials[0] }}
|
||||
<br />
|
||||
<span class="tag is-danger">pass</span>
|
||||
{{ ui_credentials.password }}
|
||||
{{ ui_credentials[1] }}
|
||||
</BulmaSecret>
|
||||
</dd>
|
||||
</dl>
|
||||
|
@ -122,7 +122,7 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { ConfigModel, DoorsSaved, NumStrDict } from "@/lib/api";
|
||||
import { ConfigModel, Credentials, DoorsSaved, NumStrDict } from "@/lib/api";
|
||||
import { DateTime } from "luxon";
|
||||
import { Options, Vue } from "vue-class-component";
|
||||
|
||||
|
@ -130,11 +130,6 @@ import BulmaDrawer from "../bulma/Drawer.vue";
|
|||
import BulmaSecret from "../bulma/Secret.vue";
|
||||
import CountDown from "../CountDown.vue";
|
||||
|
||||
interface Credentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
@Options({
|
||||
components: {
|
||||
BulmaDrawer,
|
||||
|
@ -170,8 +165,8 @@ export default class extends Vue {
|
|||
public day_parts: NumStrDict = {};
|
||||
public num_user_doors = 0;
|
||||
public next_door: number | null = null;
|
||||
public dav_credentials: Credentials = { username: "", password: "" };
|
||||
public ui_credentials: Credentials = { username: "", password: "" };
|
||||
public dav_credentials: Credentials = ["", ""];
|
||||
public ui_credentials: Credentials = ["", ""];
|
||||
|
||||
public fmt_puzzle_date(name: keyof ConfigModel["puzzle"]): string {
|
||||
const iso_date = this.config_model.puzzle[name];
|
||||
|
@ -200,25 +195,15 @@ export default class extends Vue {
|
|||
|
||||
public load_dav_credentials(): void {
|
||||
this.$advent22
|
||||
.api_get<string[]>("admin/dav_credentials")
|
||||
.then(([username, password]) => {
|
||||
this.dav_credentials = {
|
||||
username: username,
|
||||
password: password,
|
||||
};
|
||||
})
|
||||
.api_get<Credentials>("admin/dav_credentials")
|
||||
.then((creds) => (this.dav_credentials = creds))
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
public load_ui_credentials(): void {
|
||||
this.$advent22
|
||||
.api_get<string[]>("admin/ui_credentials")
|
||||
.then(([username, password]) => {
|
||||
this.ui_credentials = {
|
||||
username: username,
|
||||
password: password,
|
||||
};
|
||||
})
|
||||
.api_get<Credentials>("admin/ui_credentials")
|
||||
.then((creds) => (this.ui_credentials = creds))
|
||||
.catch(() => {});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ export interface DoorSaved {
|
|||
|
||||
export type DoorsSaved = DoorSaved[];
|
||||
|
||||
export type Credentials = [username: string, password: string];
|
||||
|
||||
export function objForEach<T>(
|
||||
obj: T,
|
||||
f: (k: keyof T, v: T[keyof T]) => void,
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
import axios, { AxiosError, AxiosInstance, ResponseType } from "axios";
|
||||
import { Credentials } from "@/lib/api";
|
||||
import axios, {
|
||||
AxiosBasicCredentials,
|
||||
AxiosError,
|
||||
AxiosInstance,
|
||||
ResponseType,
|
||||
} from "axios";
|
||||
import { App, Plugin } from "vue";
|
||||
|
||||
export class Advent22 {
|
||||
private axios: AxiosInstance;
|
||||
private api_auth = { username: "", password: "" };
|
||||
private _api_auth: Credentials = ["", ""];
|
||||
|
||||
public constructor() {
|
||||
this.axios = axios.create({
|
||||
|
@ -77,12 +83,19 @@ export class Advent22 {
|
|||
return result();
|
||||
}
|
||||
|
||||
public set_api_auth(username: string, password: string) {
|
||||
this.api_auth = { username: username, password: password };
|
||||
public get api_auth(): AxiosBasicCredentials {
|
||||
const [username, password] = this._api_auth;
|
||||
return { username: username, password: password };
|
||||
}
|
||||
|
||||
public clear_api_auth() {
|
||||
this.api_auth = { username: "", password: "" };
|
||||
public set_api_auth(): void;
|
||||
public set_api_auth(creds: Credentials): void;
|
||||
public set_api_auth(creds: Credentials = ["", ""]): void {
|
||||
this._api_auth = creds;
|
||||
}
|
||||
|
||||
public set api_auth(creds: Credentials) {
|
||||
this.set_api_auth(creds);
|
||||
}
|
||||
|
||||
public api_url(): string;
|
||||
|
|
Loading…
Reference in a new issue