Updates and more

This commit is contained in:
2023-11-12 22:43:42 +01:00
parent 7450ecdabb
commit 3889f28eb8
43 changed files with 5188 additions and 322 deletions

View File

@@ -1,5 +1,5 @@
import type {Server} from "../types/data.ts";
import {ServerSchema} from "../types/data.ts";
import type {Player, Server} from "../types/data.ts";
import {PlayerSchema, ServerSchema} from "../types/data.ts";
import {fetchWithToken} from "./repo.ts";
export class DataRepo {
@@ -8,4 +8,8 @@ export class DataRepo {
public async getServer(): Promise<Server> {
return await fetchWithToken(this.token, "/data/server").then(value => value.json()).then(value => ServerSchema.parse(value));
}
public async getMe(): Promise<Player> {
return await fetchWithToken(this.token, "/data/me").then(value => value.json()).then(value => PlayerSchema.parse(value));
}
}

View File

@@ -2,7 +2,6 @@ import type {Page, PageList} from "../types/page.ts";
import {fetchWithToken} from "./repo.ts";
import {PageListSchema, PageSchema} from "../types/page.ts";
import {bytesToBase64} from "../admin/util.ts";
import {branches} from "../stores/stores.ts";
export class PageRepo {
constructor(private token: string) {}

View File

@@ -6,6 +6,7 @@ import {PageRepo} from "./page.ts";
import {DataRepo} from "./data.ts";
import { AES, enc, format } from "crypto-js";
import {SchematicRepo} from "./schem.ts";
export { EventRepo } from "./event.js"
@@ -29,3 +30,4 @@ 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))

View File

@@ -0,0 +1,33 @@
import {fetchWithToken} from "./repo.ts";
import type {SchematicCode, SchematicInfo, SchematicList} from "../types/schem.ts";
import {SchematicCodeSchema, SchematicInfoSchema, SchematicListSchema} from "../types/schem.ts";
export class SchematicRepo {
constructor(private token: string) {}
public async getRootSchematicList(): Promise<SchematicList> {
return await fetchWithToken(this.token, "/schem").then(value => value.json()).then(value => SchematicListSchema.parse(value));
}
public async getSchematicList(id: number): Promise<SchematicList> {
return await fetchWithToken(this.token, `/schem/${id}/list`).then(value => value.json()).then(value => SchematicListSchema.parse(value));
}
public async getSchematicInfo(id: number): Promise<SchematicInfo> {
return await fetchWithToken(this.token, `/schem/${id}`).then(value => value.json()).then(value => SchematicInfoSchema.parse(value));
}
public async createDownload(id: number): Promise<SchematicCode> {
return await fetchWithToken(this.token, `/schem/${id}/download`).then(value => value.json()).then(value => SchematicCodeSchema.parse(value));
}
public async uploadSchematic(name: string, content: string) {
return await fetchWithToken(this.token, `/schem`, {
method: "POST",
body: JSON.stringify({
name,
content
})
})
}
}