Skip to content

Commit

Permalink
fix: add token to file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
williamhorning committed Dec 22, 2024
1 parent f05fc01 commit b134354
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/rvapi/deno.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/rvapi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
12 changes: 11 additions & 1 deletion packages/rvapi/src/media/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b134354

Please sign in to comment.