Some Code Cleanup

This commit is contained in:
2023-12-25 21:54:40 +01:00
parent a2687083e0
commit 3108d9bf20
61 changed files with 305 additions and 247 deletions

View File

@@ -18,18 +18,16 @@
*/
import {derived, writable} from "svelte/store";
import {EventRepo} from "./event.js";
import {FightRepo} from "./fight.js";
import {PermsRepo} from "./perms.js";
import {PageRepo} from "./page.ts";
import {DataRepo} from "./data.ts";
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, format } from "crypto-js";
import {SchematicRepo} from "./schem.ts";
import {StatsRepo} from "./stats.ts";
import {AuthRepo} from "./auth.ts";
export { EventRepo } from "./event.js"
import { AES, enc } from "crypto-js";
export const apiUrl = import.meta.env.PUBLIC_API_SERVER;
const secret = import.meta.env.PUBLIC_SECRET;
@@ -43,14 +41,14 @@ function decryptToken(token: string): string {
}
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 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))
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));