Skip to content

Commit

Permalink
add uploads to client
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Jul 8, 2024
1 parent ec2beee commit 0dda8a7
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { rest_api } from './rest.ts';
import { socket } from './socket.ts';
import { uploads } from './uploads.ts';

/** options used by the client to login */
export interface client_login_options {
Expand All @@ -11,6 +12,8 @@ export interface client_login_options {
api_url: string;
/** socket url */
socket_url: string;
/** uploads url */
uploads_url: string;
}

/** options used by the client to signup */
Expand All @@ -25,10 +28,13 @@ export class client {
api: rest_api;
/** access to websocket events */
socket: socket;
/** access to uploads */
uploads: uploads;

private constructor(api: rest_api, socket: socket) {
constructor(api: rest_api, socket: socket, uploads: uploads) {
this.api = api;
this.socket = socket;
this.uploads = uploads;
}

/** signup for an account and login */
Expand All @@ -44,7 +50,12 @@ export class client {

const ws = await socket.connect({ ...opts, api_token: rest.api_token });

return new client(rest, ws);
const u = new uploads({
base_url: opts.uploads_url,
token: rest.api_token,
});

return new client(rest, ws, u);
}

/** login to an account */
Expand All @@ -57,6 +68,11 @@ export class client {

const ws = await socket.connect({ ...opts, api_token: rest.api_token });

return new client(rest, ws);
const u = new uploads({
base_url: opts.uploads_url,
token: rest.api_token,
});

return new client(rest, ws, u);
}
}

0 comments on commit 0dda8a7

Please sign in to comment.