Some Code Cleanup
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
Chaoscaot 2023-12-27 19:16:54 +01:00
Ursprung 3108d9bf20
Commit 9a16c4b560
38 geänderte Dateien mit 87 neuen und 105 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,6 @@
"@astrojs/tailwind": "^5.0.4", "@astrojs/tailwind": "^5.0.4",
"@astropub/icons": "^0.2.0", "@astropub/icons": "^0.2.0",
"@types/color": "^3.0.6", "@types/color": "^3.0.6",
"@types/crypto-js": "^4.2.1",
"@types/node": "^20.10.5", "@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^6.15.0", "@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0", "@typescript-eslint/parser": "^6.15.0",
@ -52,7 +51,6 @@
"chartjs-adapter-dayjs-4": "^1.0.4", "chartjs-adapter-dayjs-4": "^1.0.4",
"chartjs-adapter-moment": "^1.0.1", "chartjs-adapter-moment": "^1.0.1",
"color": "^4.2.3", "color": "^4.2.3",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"easymde": "^2.18.0", "easymde": "^2.18.0",
"flowbite": "^1.8.1", "flowbite": "^1.8.1",

Datei anzeigen

@ -38,9 +38,6 @@ dependencies:
color: color:
specifier: ^4.2.3 specifier: ^4.2.3
version: 4.2.3 version: 4.2.3
crypto-js:
specifier: ^4.2.0
version: 4.2.0
dayjs: dayjs:
specifier: ^1.11.10 specifier: ^1.11.10
version: 1.11.10 version: 1.11.10
@ -85,9 +82,6 @@ devDependencies:
'@types/color': '@types/color':
specifier: ^3.0.6 specifier: ^3.0.6
version: 3.0.6 version: 3.0.6
'@types/crypto-js':
specifier: ^4.2.1
version: 4.2.1
'@types/node': '@types/node':
specifier: ^20.10.5 specifier: ^20.10.5
version: 20.10.5 version: 20.10.5
@ -1083,10 +1077,6 @@ packages:
'@types/color-convert': 2.0.3 '@types/color-convert': 2.0.3
dev: true dev: true
/@types/crypto-js@4.2.1:
resolution: {integrity: sha512-FSPGd9+OcSok3RsM0UZ/9fcvMOXJ1ENE/ZbLfOPlBWj7BgXtEAM8VYfTtT760GiLbQIMoVozwVuisjvsVwqYWw==}
dev: true
/@types/debug@4.1.12: /@types/debug@4.1.12:
resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==}
dependencies: dependencies:
@ -1975,10 +1965,6 @@ packages:
shebang-command: 2.0.0 shebang-command: 2.0.0
which: 2.0.2 which: 2.0.2
/crypto-js@4.2.0:
resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==}
dev: false
/css-declaration-sorter@7.1.1(postcss@8.4.32): /css-declaration-sorter@7.1.1(postcss@8.4.32):
resolution: {integrity: sha512-dZ3bVTEEc1vxr3Bek9vGwfB5Z6ESPULhcRvO472mfjVnj8jRcTnKO8/JTczlvxM10Myb+wBM++1MtdO76eWcaQ==} resolution: {integrity: sha512-dZ3bVTEEc1vxr3Bek9vGwfB5Z6ESPULhcRvO472mfjVnj8jRcTnKO8/JTczlvxM10Myb+wBM++1MtdO76eWcaQ==}
engines: {node: ^14 || ^16 || >=18} engines: {node: ^14 || ^16 || >=18}

Datei anzeigen

@ -19,9 +19,10 @@
<script lang="ts"> <script lang="ts">
import {t} from "astro-i18n" import {t} from "astro-i18n"
import {dataRepo, schemRepo} from "@repo/repo";
import SchematicList from "./dashboard/SchematicList.svelte"; import SchematicList from "./dashboard/SchematicList.svelte";
import UserInfo from "./dashboard/UserInfo.svelte"; import UserInfo from "./dashboard/UserInfo.svelte";
import {dataRepo} from "@repo/data.ts";
import {schemRepo} from "@repo/schem.ts";
let userFetch = getUser(); let userFetch = getUser();
let schematicFetch = getSchematics(); let schematicFetch = getSchematics();

Datei anzeigen

@ -18,8 +18,8 @@
--> -->
<script lang="ts"> <script lang="ts">
import {statsRepo} from "@repo/repo.ts";
import {t} from "astro-i18n"; import {t} from "astro-i18n";
import {statsRepo} from "@repo/stats.ts";
export let gamemode: string; export let gamemode: string;

Datei anzeigen

@ -18,9 +18,9 @@
--> -->
<script lang="ts"> <script lang="ts">
import {statsRepo} from "@repo/repo.ts";
import FightStatsChart from "./FightStatsChart.svelte"; import FightStatsChart from "./FightStatsChart.svelte";
import {t} from "astro-i18n"; import {t} from "astro-i18n";
import {statsRepo} from "@repo/stats.ts";
let request = getStats(); let request = getStats();

Datei anzeigen

@ -28,7 +28,8 @@
let error: string = ""; let error: string = "";
async function login() { async function login() {
let {tokenStore, authRepo} = await import("./repo/repo.ts"); let {tokenStore} = await import("./repo/repo.ts");
let {authRepo} = await import("./repo/auth.ts");
if (username === "" || pw === "") { if (username === "" || pw === "") {
pw = ""; pw = "";
error = t("login.error"); error = t("login.error");

Datei anzeigen

@ -20,11 +20,11 @@
<script lang="ts"> <script lang="ts">
import {ArrowLeftSolid} from "flowbite-svelte-icons"; import {ArrowLeftSolid} from "flowbite-svelte-icons";
import {Button, Card, Navbar, NavBrand, Spinner} from "flowbite-svelte"; import {Button, Card, Navbar, NavBrand, Spinner} from "flowbite-svelte";
import {pageRepo} from "@repo/repo.ts";
import {mapToMap, nameRegex} from "../util.ts"; import {mapToMap, nameRegex} from "../util.ts";
import TypeAheadSearch from "../components/TypeAheadSearch.svelte"; import TypeAheadSearch from "../components/TypeAheadSearch.svelte";
import {branches} from "@stores/stores.ts"; import {branches} from "@stores/stores.ts";
import Editor from "./edit/Editor.svelte"; import Editor from "./edit/Editor.svelte";
import {pageRepo} from "@repo/page.ts";
$: pagesFuture = $pageRepo.listPages(selectedBranch); $: pagesFuture = $pageRepo.listPages(selectedBranch);

Datei anzeigen

@ -22,8 +22,8 @@
import EventEdit from "./event/EventEdit.svelte"; import EventEdit from "./event/EventEdit.svelte";
import {ArrowLeftSolid} from "flowbite-svelte-icons"; import {ArrowLeftSolid} from "flowbite-svelte-icons";
import FightList from "./event/FightList.svelte"; import FightList from "./event/FightList.svelte";
import {eventRepo} from "@repo/repo.ts";
import TeamList from "./event/TeamList.svelte"; import TeamList from "./event/TeamList.svelte";
import {eventRepo} from "@repo/event.ts";
export let params: { id: number }; export let params: { id: number };

Datei anzeigen

@ -20,8 +20,8 @@
<script lang="ts"> <script lang="ts">
import {Navbar, NavBrand, Spinner, TabItem, Tabs} from "flowbite-svelte"; import {Navbar, NavBrand, Spinner, TabItem, Tabs} from "flowbite-svelte";
import {ArrowLeftSolid} from "flowbite-svelte-icons"; import {ArrowLeftSolid} from "flowbite-svelte-icons";
import {eventRepo} from "@repo/repo.ts";
import GroupGenerator from "./generate/GroupGenerator.svelte"; import GroupGenerator from "./generate/GroupGenerator.svelte";
import {eventRepo} from "@repo/event.ts";
export let params: { id: number }; export let params: { id: number };

Datei anzeigen

@ -23,7 +23,8 @@
import {PlusSolid} from "flowbite-svelte-icons"; import {PlusSolid} from "flowbite-svelte-icons";
import EventCard from "./home/EventCard.svelte"; import EventCard from "./home/EventCard.svelte";
import CreateEventModal from "./home/CreateEventModal.svelte"; import CreateEventModal from "./home/CreateEventModal.svelte";
import {eventRepo, tokenStore} from "@repo/repo.ts"; import {eventRepo} from "@repo/event.ts";
import {tokenStore} from "@repo/repo.ts";
let events = $eventRepo.listEvents() let events = $eventRepo.listEvents()
let showAdd = false let showAdd = false

Datei anzeigen

@ -21,8 +21,8 @@
import {Button, Card, Checkbox, Input, Label, Navbar, NavBrand, Radio, Spinner} from "flowbite-svelte"; import {Button, Card, Checkbox, Input, Label, Navbar, NavBrand, Radio, Spinner} from "flowbite-svelte";
import {ArrowLeftSolid} from "flowbite-svelte-icons"; import {ArrowLeftSolid} from "flowbite-svelte-icons";
import {players} from "@stores/stores.ts"; import {players} from "@stores/stores.ts";
import {permsRepo} from "@repo/repo.ts";
import {capitalize} from "../util.ts"; import {capitalize} from "../util.ts";
import {permsRepo} from "@repo/perms.ts";
let search = ""; let search = "";
$: lowerCaseSearch = search.toLowerCase(); $: lowerCaseSearch = search.toLowerCase();

Datei anzeigen

@ -21,12 +21,12 @@
import {Spinner, Toolbar, ToolbarButton, ToolbarGroup} from "flowbite-svelte"; import {Spinner, Toolbar, ToolbarButton, ToolbarGroup} from "flowbite-svelte";
import {json} from "@codemirror/lang-json"; import {json} from "@codemirror/lang-json";
import CodeMirror from "svelte-codemirror-editor"; import CodeMirror from "svelte-codemirror-editor";
import {pageRepo} from "@repo/repo.ts";
import {base64ToBytes} from "../../util.ts"; import {base64ToBytes} from "../../util.ts";
import type {Page} from "@type/page.ts"; import type {Page} from "@type/page.ts";
import {materialDark} from '@ddietr/codemirror-themes/material-dark.js' import {materialDark} from '@ddietr/codemirror-themes/material-dark.js'
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import MDEMarkdownEditor from "./MDEMarkdownEditor.svelte"; import MDEMarkdownEditor from "./MDEMarkdownEditor.svelte";
import {pageRepo} from "@repo/page.ts";
export let pageId: number; export let pageId: number;
export let branch: string; export let branch: string;

Datei anzeigen

@ -23,8 +23,7 @@
import {schemTypes} from "@stores/stores.ts"; import {schemTypes} from "@stores/stores.ts";
import dayjs from "dayjs"; import dayjs from "dayjs";
import utc from "dayjs/plugin/utc" import utc from "dayjs/plugin/utc"
import type {UpdateEvent} from "@repo/event.ts"; import {eventRepo, type UpdateEvent} from "@repo/event.ts";
import {eventRepo} from "@repo/repo.ts";
import ErrorModal from "../../components/ErrorModal.svelte"; import ErrorModal from "../../components/ErrorModal.svelte";
import {replace} from "svelte-spa-router"; import {replace} from "svelte-spa-router";
import {CheckCircleOutline} from "flowbite-svelte-icons"; import {CheckCircleOutline} from "flowbite-svelte-icons";

Datei anzeigen

@ -23,8 +23,8 @@
import type {EventFight, ExtendedEvent} from "@type/event.ts"; import type {EventFight, ExtendedEvent} from "@type/event.ts";
import FightEditModal from "./modals/FightEditModal.svelte"; import FightEditModal from "./modals/FightEditModal.svelte";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import {fightRepo} from "@repo/repo.ts";
import {isWide} from "@stores/stores.ts"; import {isWide} from "@stores/stores.ts";
import {fightRepo} from "@repo/fight.ts";
export let fight: EventFight; export let fight: EventFight;
export let data: ExtendedEvent; export let data: ExtendedEvent;

Datei anzeigen

@ -36,10 +36,9 @@
} from "flowbite-svelte-icons"; } from "flowbite-svelte-icons";
import FightCard from "./FightCard.svelte"; import FightCard from "./FightCard.svelte";
import CreateFightModal from "./modals/CreateFightModal.svelte"; import CreateFightModal from "./modals/CreateFightModal.svelte";
import {fightRepo} from "@repo/repo.ts";
import {groups, players} from "@stores/stores.ts"; import {groups, players} from "@stores/stores.ts";
import TypeAheadSearch from "../../components/TypeAheadSearch.svelte"; import TypeAheadSearch from "../../components/TypeAheadSearch.svelte";
import type {UpdateFight} from "@repo/fight.ts"; import {fightRepo, type UpdateFight} from "@repo/fight.ts";
import dayjs from "dayjs"; import dayjs from "dayjs";
import duration from "dayjs/plugin/duration" import duration from "dayjs/plugin/duration"
dayjs.extend(duration) dayjs.extend(duration)

Datei anzeigen

@ -21,10 +21,10 @@
import {Button, Modal} from "flowbite-svelte"; import {Button, Modal} from "flowbite-svelte";
import type {ExtendedEvent} from "@type/event.ts"; import type {ExtendedEvent} from "@type/event.ts";
import FightEditPart from "../../../components/FightEditPart.svelte"; import FightEditPart from "../../../components/FightEditPart.svelte";
import {fightRepo} from "@repo/repo.ts";
import ErrorModal from "../../../components/ErrorModal.svelte"; import ErrorModal from "../../../components/ErrorModal.svelte";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import dayjs from "dayjs"; import dayjs from "dayjs";
import {fightRepo} from "@repo/fight.ts";
let dispatch = createEventDispatcher(); let dispatch = createEventDispatcher();

Datei anzeigen

@ -21,8 +21,7 @@
import {Button, Modal} from "flowbite-svelte"; import {Button, Modal} from "flowbite-svelte";
import type {EventFight, ExtendedEvent} from "@type/event.ts"; import type {EventFight, ExtendedEvent} from "@type/event.ts";
import FightEditPart from "../../../components/FightEditPart.svelte"; import FightEditPart from "../../../components/FightEditPart.svelte";
import type {UpdateFight} from "@repo/fight.ts"; import {fightRepo, type UpdateFight} from "@repo/fight.ts";
import {fightRepo} from "@repo/repo.ts";
import ErrorModal from "../../../components/ErrorModal.svelte"; import ErrorModal from "../../../components/ErrorModal.svelte";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import dayjs from "dayjs"; import dayjs from "dayjs";

Datei anzeigen

@ -25,9 +25,9 @@
import {Button, Input, Label, Modal, Range, Select} from "flowbite-svelte"; import {Button, Input, Label, Modal, Range, Select} from "flowbite-svelte";
import {gamemodes, maps} from "@stores/stores.ts"; import {gamemodes, maps} from "@stores/stores.ts";
import {PlusSolid} from "flowbite-svelte-icons"; import {PlusSolid} from "flowbite-svelte-icons";
import {fightRepo} from "@repo/repo.ts";
import {replace} from "svelte-spa-router"; import {replace} from "svelte-spa-router";
import dayjs from "dayjs"; import dayjs from "dayjs";
import {fightRepo} from "@repo/fight.ts";
export let data: ExtendedEvent; export let data: ExtendedEvent;
$: teams = new Map<number, Team>(data.teams.map(team => [team.id, team])); $: teams = new Map<number, Team>(data.teams.map(team => [team.id, team]));

Datei anzeigen

@ -21,8 +21,8 @@
import {Button, Input, Label, Modal} from "flowbite-svelte"; import {Button, Input, Label, Modal} from "flowbite-svelte";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import ErrorModal from "../../components/ErrorModal.svelte"; import ErrorModal from "../../components/ErrorModal.svelte";
import {eventRepo} from "@repo/repo.ts";
import dayjs from "dayjs"; import dayjs from "dayjs";
import {eventRepo} from "@repo/event.ts";
export let open = false; export let open = false;
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();

Datei anzeigen

@ -19,10 +19,10 @@
<script lang="ts"> <script lang="ts">
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import {schemRepo} from "@repo/repo";
import {Modal, Spinner} from "flowbite-svelte"; import {Modal, Spinner} from "flowbite-svelte";
import SchematicInfoModal from "./SchematicInfoModal.svelte"; import SchematicInfoModal from "./SchematicInfoModal.svelte";
import type {Player} from "@type/data.ts"; import type {Player} from "@type/data.ts";
import {schemRepo} from "@repo/schem.ts";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();

Datei anzeigen

@ -23,9 +23,9 @@
import {Modal} from "flowbite-svelte"; import {Modal} from "flowbite-svelte";
import type {SchematicInfo} from "@type/schem.ts"; import type {SchematicInfo} from "@type/schem.ts";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import {schemRepo} from "@repo/repo";
import type {Player} from "@type/data.ts"; import type {Player} from "@type/data.ts";
import dayjs from "dayjs"; import dayjs from "dayjs";
import {schemRepo} from "@repo/schem.ts";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();

Datei anzeigen

@ -19,8 +19,8 @@
<script lang="ts"> <script lang="ts">
import type {Player} from "@type/data.ts"; import type {Player} from "@type/data.ts";
import {statsRepo} from "@repo/repo.ts";
import {astroI18n, t} from "astro-i18n" import {astroI18n, t} from "astro-i18n"
import {statsRepo} from "@repo/stats.ts";
export let user: Player; export let user: Player;

Datei anzeigen

@ -19,8 +19,8 @@
<script lang="ts"> <script lang="ts">
import {Modal} from "flowbite-svelte"; import {Modal} from "flowbite-svelte";
import {schemRepo} from "@repo/repo.ts";
import {createEventDispatcher} from "svelte"; import {createEventDispatcher} from "svelte";
import {schemRepo} from "@repo/schem.ts";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();

Datei anzeigen

@ -20,9 +20,10 @@
<script lang="ts"> <script lang="ts">
import {t} from "astro-i18n"; import {t} from "astro-i18n";
import type {Player} from "@type/data.ts"; import type {Player} from "@type/data.ts";
import {authRepo, tokenStore} from "@repo/repo.ts";
import {l} from "@utils/util.ts"; import {l} from "@utils/util.ts";
import Statistics from "./Statistics.svelte"; import Statistics from "./Statistics.svelte";
import {authRepo} from "@repo/auth.ts";
import {tokenStore} from "@repo/repo.ts";
export let user: Player; export let user: Player;

Datei anzeigen

@ -17,7 +17,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {fetchWithToken} from "./repo.ts"; import {fetchWithToken, tokenStore} from "./repo.ts";
import {derived} from "svelte/store";
export class AuthRepo { export class AuthRepo {
constructor(private token: string) { constructor(private token: string) {
@ -39,3 +40,5 @@ export class AuthRepo {
}); });
} }
} }
export const authRepo = derived(tokenStore, ($token) => new AuthRepo($token));

Datei anzeigen

@ -19,7 +19,8 @@
import type {Player, Server} from "@type/data.ts"; import type {Player, Server} from "@type/data.ts";
import {PlayerSchema, ServerSchema} from "@type/data.ts"; import {PlayerSchema, ServerSchema} from "@type/data.ts";
import {fetchWithToken} from "./repo.ts"; import {fetchWithToken, tokenStore} from "./repo.ts";
import {derived} from "svelte/store";
export class DataRepo { export class DataRepo {
constructor(private token: string) {} constructor(private token: string) {}
@ -32,3 +33,5 @@ export class DataRepo {
return await fetchWithToken(this.token, "/data/me").then(value => value.json()).then(PlayerSchema.parse); return await fetchWithToken(this.token, "/data/me").then(value => value.json()).then(PlayerSchema.parse);
} }
} }
export const dataRepo = derived(tokenStore, ($token) => new DataRepo($token));

Datei anzeigen

@ -18,10 +18,11 @@
*/ */
import type {ExtendedEvent, ShortEvent, SWEvent} from "@type/event"; import type {ExtendedEvent, ShortEvent, SWEvent} from "@type/event";
import {fetchWithToken} from "./repo"; import {fetchWithToken, tokenStore} from "./repo";
import {ExtendedEventSchema, ShortEventSchema, SWEventSchema} from "@type/event.js"; import {ExtendedEventSchema, ShortEventSchema, SWEventSchema} from "@type/event.js";
import {z} from "zod"; import {z} from "zod";
import type {Dayjs} from "dayjs"; import type {Dayjs} from "dayjs";
import {derived} from "svelte/store";
export interface CreateEvent { export interface CreateEvent {
name: string name: string
@ -95,3 +96,5 @@ export class EventRepo {
return res.ok; return res.ok;
} }
} }
export const eventRepo = derived(tokenStore, ($token) => new EventRepo($token));

Datei anzeigen

@ -18,10 +18,11 @@
*/ */
import type {EventFight} from "@type/event.js"; import type {EventFight} from "@type/event.js";
import {fetchWithToken} from "./repo"; import {fetchWithToken, tokenStore} from "./repo";
import {z} from "zod"; import {z} from "zod";
import {EventFightSchema} from "@type/event.js"; import {EventFightSchema} from "@type/event.js";
import type {Dayjs} from "dayjs"; import type {Dayjs} from "dayjs";
import {derived} from "svelte/store";
export interface CreateFight { export interface CreateFight {
spielmodus: string spielmodus: string
@ -86,12 +87,14 @@ export class FightRepo {
} }
public async deleteFight(fightId: number): Promise<void> { public async deleteFight(fightId: number): Promise<void> {
let res = await fetchWithToken(this.token, `/fights/${fightId}`, { const res = await fetchWithToken(this.token, `/fights/${fightId}`, {
method: "DELETE" method: "DELETE"
}) });
if (!res.ok) { if (!res.ok) {
throw new Error("Could not delete fight: " + res.statusText); throw new Error("Could not delete fight: " + res.statusText);
} }
} }
} }
export const fightRepo = derived(tokenStore, ($token) => new FightRepo($token));

Datei anzeigen

@ -18,10 +18,11 @@
*/ */
import type {Page, PageList} from "@type/page.ts"; import type {Page, PageList} from "@type/page.ts";
import {fetchWithToken} from "./repo.ts"; import {fetchWithToken, tokenStore} from "./repo.ts";
import {PageListSchema, PageSchema} from "@type/page.ts"; import {PageListSchema, PageSchema} from "@type/page.ts";
import {bytesToBase64} from "../admin/util.ts"; import {bytesToBase64} from "../admin/util.ts";
import {z} from "zod"; import {z} from "zod";
import {derived} from "svelte/store";
export class PageRepo { export class PageRepo {
constructor(private token: string) {} constructor(private token: string) {}
@ -75,3 +76,5 @@ export class PageRepo {
await fetchWithToken(this.token, `/page/${id}?branch=${branch}`, {method: "DELETE", body: JSON.stringify({message, sha})}); await fetchWithToken(this.token, `/page/${id}?branch=${branch}`, {method: "DELETE", body: JSON.stringify({message, sha})});
} }
} }
export const pageRepo = derived(tokenStore, ($token) => new PageRepo($token));

Datei anzeigen

@ -18,8 +18,9 @@
*/ */
import type {Perms, UserPerms} from "@type/perms.js"; import type {Perms, UserPerms} from "@type/perms.js";
import {fetchWithToken} from "./repo"; import {fetchWithToken, tokenStore} from "./repo";
import {PermsSchema, UserPermsSchema} from "@type/perms.js"; import {PermsSchema, UserPermsSchema} from "@type/perms.js";
import {derived} from "svelte/store";
export class PermsRepo { export class PermsRepo {
constructor(private token: string) {} constructor(private token: string) {}
@ -68,3 +69,5 @@ export class PermsRepo {
} }
} }
} }
export const permsRepo = derived(tokenStore, ($token) => new PermsRepo($token));

Datei anzeigen

@ -17,38 +17,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {derived, writable} from "svelte/store"; import {writable} from "svelte/store";
import {EventRepo} from "./event";
import {FightRepo} from "./fight";
import {PermsRepo} from "./perms";
import {PageRepo} from "./page";
import {DataRepo} from "./data";
import {SchematicRepo} from "./schem";
import {StatsRepo} from "./stats";
import {AuthRepo} from "./auth";
import { AES, enc } from "crypto-js"; export const fetchWithToken = (token: string, url: string, params: RequestInit = {}) =>
fetch(`${import.meta.env.PUBLIC_API_SERVER}${url}`, {...params, headers: {...(token !== "" ? {"Authorization": "Bearer " + (token)}:{}), "Content-Type": "application/json", ...params.headers}})
export const apiUrl = import.meta.env.PUBLIC_API_SERVER; .then(value => {
const secret = import.meta.env.PUBLIC_SECRET; if (value.status === 401) {
tokenStore.set("");
function encryptToken(token: string): string {
return AES.encrypt(token, secret).toString();
} }
return value;
});
function decryptToken(token: string): string { export const tokenStore = writable((localStorage.getItem("sw-session") ?? ""));
return AES.decrypt(token, secret).toString(enc.Utf8); tokenStore.subscribe((value) => localStorage.setItem("sw-session", value));
}
export const fetchWithToken = (token: string, url: string, params: RequestInit = {}) => fetch(`${apiUrl}${url}`, {...params, headers: {...(token !== "" ? {"Authorization": "Bearer " + (token)}:{}), "Content-Type": "application/json", ...params.headers}});
export const tokenStore = writable(decryptToken(localStorage.getItem("sw-session") ?? ""));
tokenStore.subscribe((value) => localStorage.setItem("sw-session", encryptToken(value)));
export const eventRepo = derived(tokenStore, ($token) => new EventRepo($token));
export const fightRepo = derived(tokenStore, ($token) => new FightRepo($token));
export const permsRepo = derived(tokenStore, ($token) => new PermsRepo($token));
export const pageRepo = derived(tokenStore, ($token) => new PageRepo($token));
export const dataRepo = derived(tokenStore, ($token) => new DataRepo($token));
export const schemRepo = derived(tokenStore, ($token) => new SchematicRepo($token));
export const statsRepo = derived(tokenStore, ($token) => new StatsRepo($token));
export const authRepo = derived(tokenStore, ($token) => new AuthRepo($token));

Datei anzeigen

@ -17,9 +17,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {fetchWithToken} from "./repo.ts"; import {fetchWithToken, tokenStore} from "./repo.ts";
import type {SchematicCode, SchematicInfo, SchematicList} from "@type/schem.ts"; import type {SchematicCode, SchematicInfo, SchematicList} from "@type/schem.ts";
import {SchematicCodeSchema, SchematicInfoSchema, SchematicListSchema} from "@type/schem.ts"; import {SchematicCodeSchema, SchematicInfoSchema, SchematicListSchema} from "@type/schem.ts";
import {derived} from "svelte/store";
export class SchematicRepo { export class SchematicRepo {
constructor(private token: string) {} constructor(private token: string) {}
@ -50,3 +51,5 @@ export class SchematicRepo {
}); });
} }
} }
export const schemRepo = derived(tokenStore, ($token) => new SchematicRepo($token));

Datei anzeigen

@ -18,8 +18,9 @@
*/ */
import type {FightStats, Ranking, UserStats} from "@type/stats.ts"; import type {FightStats, Ranking, UserStats} from "@type/stats.ts";
import {fetchWithToken} from "./repo.ts"; import {fetchWithToken, tokenStore} from "./repo.ts";
import {FightStatsSchema, RankingSchema, UserStatsSchema} from "@type/stats.ts"; import {FightStatsSchema, RankingSchema, UserStatsSchema} from "@type/stats.ts";
import {derived} from "svelte/store";
export class StatsRepo { export class StatsRepo {
@ -37,3 +38,5 @@ export class StatsRepo {
return await fetchWithToken(this.token, `/stats/user/${id}`).then(value => value.json()).then(UserStatsSchema.parse); return await fetchWithToken(this.token, `/stats/user/${id}`).then(value => value.json()).then(UserStatsSchema.parse);
} }
} }
export const statsRepo = derived(tokenStore, ($token) => new StatsRepo($token));

Datei anzeigen

@ -23,8 +23,10 @@ import {cached, cachedFamily} from "./cached";
import type {Team} from "@type/team.ts"; import type {Team} from "@type/team.ts";
import {TeamSchema} from "@type/team"; import {TeamSchema} from "@type/team";
import {derived, get, writable} from "svelte/store"; import {derived, get, writable} from "svelte/store";
import {dataRepo, fetchWithToken, pageRepo, tokenStore} from "@repo/repo.ts";
import {z} from "zod"; import {z} from "zod";
import {fetchWithToken, tokenStore} from "@repo/repo.ts";
import {pageRepo} from "@repo/page.ts";
import {dataRepo} from "@repo/data.ts";
export const schemTypes = cached<SchematicType[]>([], () => export const schemTypes = cached<SchematicType[]>([], () =>
fetchWithToken(get(tokenStore), "/data/schematicTypes") fetchWithToken(get(tokenStore), "/data/schematicTypes")

Datei anzeigen

@ -88,12 +88,12 @@ const ogImage = await getImage({
)} )}
<Content /> <Content />
<script> <script>
import type {ExtendedEvent} from "@types/event";
import FightTable from "@components/FightTable.svelte"; import FightTable from "@components/FightTable.svelte";
// @ts-expect-error Import Schenanigans // @ts-expect-error Import Schenanigans
import {get} from "svelte/store"; import {get} from "svelte/store";
import {eventRepo} from "@repo/repo";
import GroupTable from "@components/GroupTable.svelte"; import GroupTable from "@components/GroupTable.svelte";
import {eventRepo} from "../../components/repo/event";
import type {ExtendedEvent} from "@type/event";
const eventMounts: Map<string, ((ev: ExtendedEvent) => void)[]> = new Map(); const eventMounts: Map<string, ((ev: ExtendedEvent) => void)[]> = new Map();
class FightTableElement extends HTMLElement { class FightTableElement extends HTMLElement {

Datei anzeigen

@ -5,10 +5,9 @@ import {t} from "astro-i18n";
--- ---
<PageLayout title={t("dashboard.page")}> <PageLayout title={t("dashboard.page")}>
<script> <script is:inline>
import {AES} from "crypto-js";
import {l} from "../util/util"; import {l} from "../util/util";
if (AES.decrypt(localStorage.getItem("sw-session") ?? "", import.meta.env.PUBLIC_SECRET)?.toString() === "") { if ((localStorage.getItem("sw-session") ?? "") === "") {
window.location.href = l("/login"); window.location.href = l("/login");
} }
</script> </script>

Datei anzeigen

@ -7,11 +7,10 @@ import localBau from "@images/2023-10-08_20.43.43.png";
--- ---
<NavbarLayout title={t("login.page")}> <NavbarLayout title={t("login.page")}>
<script> <script is:inline>
import {l} from "../util/util"; import {l} from "../util/util";
import {AES} from "crypto-js";
if (AES.decrypt(localStorage.getItem("sw-session") ?? "", import.meta.env.PUBLIC_SECRET)?.toString() !== "") { if ((localStorage.getItem("sw-session") ?? "") !== "") {
window.location.href = l("/dashboard"); window.location.href = l("/dashboard");
} }
</script> </script>

Datei anzeigen

@ -1,8 +1,3 @@
setup:
- "echo 'PUBLIC_API_SERVER=https://steamwar.de/eventplanner-api/
PUBLIC_SECRET=mae6eeheeT4Quain' > .env"
build: build:
- "echo 'PUBLIC_API_SERVER=https://steamwar.de/eventplanner-api/"
- "pnpm run ci" - "pnpm run ci"
artifacts: