various cleanup

This commit is contained in:
Jörn-Michael Miehe 2023-09-21 12:25:23 +00:00
parent 5e0f797a2f
commit 5fcc4f0684
7 changed files with 59 additions and 59 deletions

View file

@ -13,7 +13,7 @@ class User(BaseModel):
class Puzzle(BaseModel): class Puzzle(BaseModel):
# Titel # Titel
# TODO # TODO neue Route GET /user/title
title: str title: str
# Lösungswort # Lösungswort

View file

@ -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") @router.get("/day_image_names")
async def get_day_image_names( async def get_day_image_names(
_: None = Depends(require_admin), _: None = Depends(require_admin),
@ -104,6 +92,18 @@ async def get_day_image_names(
return 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") @router.get("/doors")
async def get_doors( async def get_doors(
_: None = Depends(require_admin), _: None = Depends(require_admin),

View file

@ -26,6 +26,18 @@ async def get_background_image(
return await api_return_image(await load_image(f"files/{cal_cfg.background}")) 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( @router.get(
"/image_{day}", "/image_{day}",
response_class=StreamingResponse, response_class=StreamingResponse,
@ -50,18 +62,6 @@ async def get_image_for_day(
return await api_return_image(image) 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") @router.get("/next_door")
async def get_next_door( async def get_next_door(
event_dates: EventDates = Depends(get_all_event_dates), event_dates: EventDates = Depends(get_all_event_dates),

View file

@ -38,7 +38,7 @@ export default class extends Vue {
public on_click() { public on_click() {
if (this.modelValue) { if (this.modelValue) {
// logout // logout
this.$advent22.clear_api_auth(); this.$advent22.set_api_auth();
this.$emit("update:modelValue", false); this.$emit("update:modelValue", false);
} else { } else {
// show login modal // show login modal
@ -49,7 +49,7 @@ export default class extends Vue {
public on_submit(username: string, password: string) { public on_submit(username: string, password: string) {
this.modal_visible = false; this.modal_visible = false;
this.$advent22.set_api_auth(username, password); this.$advent22.api_auth = [username, password];
this.$advent22 this.$advent22
.api_get<boolean>("admin/is_admin") .api_get<boolean>("admin/is_admin")

View file

@ -90,10 +90,10 @@
<dd class="is-family-monospace"> <dd class="is-family-monospace">
<BulmaSecret @load="load_dav_credentials"> <BulmaSecret @load="load_dav_credentials">
<span class="tag is-danger">user</span> <span class="tag is-danger">user</span>
{{ dav_credentials.username }} {{ dav_credentials[0] }}
<br /> <br />
<span class="tag is-danger">pass</span> <span class="tag is-danger">pass</span>
{{ dav_credentials.password }} {{ dav_credentials[1] }}
</BulmaSecret> </BulmaSecret>
</dd> </dd>
@ -107,10 +107,10 @@
<dd class="is-family-monospace"> <dd class="is-family-monospace">
<BulmaSecret @load="load_ui_credentials"> <BulmaSecret @load="load_ui_credentials">
<span class="tag is-danger">user</span> <span class="tag is-danger">user</span>
{{ ui_credentials.username }} {{ ui_credentials[0] }}
<br /> <br />
<span class="tag is-danger">pass</span> <span class="tag is-danger">pass</span>
{{ ui_credentials.password }} {{ ui_credentials[1] }}
</BulmaSecret> </BulmaSecret>
</dd> </dd>
</dl> </dl>
@ -122,7 +122,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { ConfigModel, DoorsSaved, NumStrDict } from "@/lib/api"; import { ConfigModel, Credentials, DoorsSaved, NumStrDict } from "@/lib/api";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
@ -130,11 +130,6 @@ import BulmaDrawer from "../bulma/Drawer.vue";
import BulmaSecret from "../bulma/Secret.vue"; import BulmaSecret from "../bulma/Secret.vue";
import CountDown from "../CountDown.vue"; import CountDown from "../CountDown.vue";
interface Credentials {
username: string;
password: string;
}
@Options({ @Options({
components: { components: {
BulmaDrawer, BulmaDrawer,
@ -170,8 +165,8 @@ export default class extends Vue {
public day_parts: NumStrDict = {}; public day_parts: NumStrDict = {};
public num_user_doors = 0; public num_user_doors = 0;
public next_door: number | null = null; public next_door: number | null = null;
public dav_credentials: Credentials = { username: "", password: "" }; public dav_credentials: Credentials = ["", ""];
public ui_credentials: Credentials = { username: "", password: "" }; public ui_credentials: Credentials = ["", ""];
public fmt_puzzle_date(name: keyof ConfigModel["puzzle"]): string { public fmt_puzzle_date(name: keyof ConfigModel["puzzle"]): string {
const iso_date = this.config_model.puzzle[name]; const iso_date = this.config_model.puzzle[name];
@ -200,25 +195,15 @@ export default class extends Vue {
public load_dav_credentials(): void { public load_dav_credentials(): void {
this.$advent22 this.$advent22
.api_get<string[]>("admin/dav_credentials") .api_get<Credentials>("admin/dav_credentials")
.then(([username, password]) => { .then((creds) => (this.dav_credentials = creds))
this.dav_credentials = {
username: username,
password: password,
};
})
.catch(() => {}); .catch(() => {});
} }
public load_ui_credentials(): void { public load_ui_credentials(): void {
this.$advent22 this.$advent22
.api_get<string[]>("admin/ui_credentials") .api_get<Credentials>("admin/ui_credentials")
.then(([username, password]) => { .then((creds) => (this.ui_credentials = creds))
this.ui_credentials = {
username: username,
password: password,
};
})
.catch(() => {}); .catch(() => {});
} }
} }

View file

@ -37,6 +37,8 @@ export interface DoorSaved {
export type DoorsSaved = DoorSaved[]; export type DoorsSaved = DoorSaved[];
export type Credentials = [username: string, password: string];
export function objForEach<T>( export function objForEach<T>(
obj: T, obj: T,
f: (k: keyof T, v: T[keyof T]) => void, f: (k: keyof T, v: T[keyof T]) => void,

View file

@ -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"; import { App, Plugin } from "vue";
export class Advent22 { export class Advent22 {
private axios: AxiosInstance; private axios: AxiosInstance;
private api_auth = { username: "", password: "" }; private _api_auth: Credentials = ["", ""];
public constructor() { public constructor() {
this.axios = axios.create({ this.axios = axios.create({
@ -77,12 +83,19 @@ export class Advent22 {
return result(); return result();
} }
public set_api_auth(username: string, password: string) { public get api_auth(): AxiosBasicCredentials {
this.api_auth = { username: username, password: password }; const [username, password] = this._api_auth;
return { username: username, password: password };
} }
public clear_api_auth() { public set_api_auth(): void;
this.api_auth = { username: "", password: "" }; 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; public api_url(): string;