better programmatic access

This commit is contained in:
2024-08-22 20:01:14 +02:00
parent 5648c76f78
commit 784c54236b
10 changed files with 2205 additions and 1866 deletions

View File

@@ -23,6 +23,10 @@ export type EncryptedFileDTO = Omit<FileDTO, 'contents'> & {
contents: string
}
type ClientOptions = {
server: string
}
type CallOptions = {
url: string
method: string
@@ -31,14 +35,21 @@ type CallOptions = {
export class PayloadToLargeError extends Error {}
export let BASE = ''
export let client: ClientOptions = {
server: 'https://cryptgeon.org',
}
export function setBase(url: string) {
BASE = url
export function setOptions(options: Partial<ClientOptions>) {
client = { ...client, ...options }
}
export function getOptions(): ClientOptions {
return client
}
export async function call(options: CallOptions) {
const response = await fetch(BASE + '/api/' + options.url, {
const url = client.server + '/api/' + options.url
const response = await fetch(url, {
method: options.method,
body: options.body === undefined ? undefined : JSON.stringify(options.body),
mode: 'cors',