Updates and more
This commit is contained in:
33
src/components/repo/schem.ts
Normal file
33
src/components/repo/schem.ts
Normal 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
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user