diff --git a/packages/rvapi/deno.json b/packages/rvapi/deno.json index bba44aa..453298d 100644 --- a/packages/rvapi/deno.json +++ b/packages/rvapi/deno.json @@ -1,6 +1,6 @@ { "name": "@jersey/rvapi", - "version": "0.0.4", + "version": "0.0.5", "exports": "./src/mod.ts", "imports": { "@denosaurs/event": "jsr:@denosaurs/event@^2.0.2", diff --git a/packages/rvapi/src/client.ts b/packages/rvapi/src/client.ts index 24f79f9..e14f350 100644 --- a/packages/rvapi/src/client.ts +++ b/packages/rvapi/src/client.ts @@ -66,6 +66,7 @@ export function createClient(opts: ClientOptions): Client { enabled: true, url: 'https://autumn.revolt.chat', }, + opts.token, ), opts, request: createRequest(opts.api_url || 'https://api.revolt.chat', { diff --git a/packages/rvapi/src/media/services.ts b/packages/rvapi/src/media/services.ts index 49f58f1..81578b3 100644 --- a/packages/rvapi/src/media/services.ts +++ b/packages/rvapi/src/media/services.ts @@ -7,11 +7,14 @@ export class MediaServices { private january: Feature; /** autumn config */ private autumn: Feature; + /** the token to use */ + private token?: string; /** create an instance of MediaServices */ - constructor(january: Feature, autumn: Feature) { + constructor(january: Feature, autumn: Feature, token?: string) { this.january = january; this.autumn = autumn; + this.token = token; } /** @@ -98,12 +101,19 @@ export class MediaServices { throw new MediaError('upload file', 'AutumnDisabled'); } + if (!this.token) { + throw new MediaError('upload file', 'NoToken'); + } + const form = new FormData(); form.append('file', file); const resp = await fetch(`${this.autumn.url}/${tag}`, { method: 'POST', body: form, + headers: { + "X-Bot-Token": this.token, + } }); const data = await resp.json();