This commit is contained in:
Zef Hemel
2022-12-05 12:14:21 +01:00
parent b24c2996be
commit e780a838b6
8 changed files with 38 additions and 41 deletions
+1 -7
View File
@@ -10,22 +10,16 @@ import { mime } from "../../plugos/deps.ts";
export class HttpSpacePrimitives implements SpacePrimitives {
fsUrl: string;
private plugUrl: string;
token?: string;
constructor(url: string, token?: string) {
constructor(url: string) {
this.fsUrl = url + "/fs";
this.plugUrl = url + "/plug";
this.token = token;
}
private async authenticatedFetch(
url: string,
options: any,
): Promise<Response> {
if (this.token) {
options.headers = options.headers || {};
options.headers["Authorization"] = `Bearer ${this.token}`;
}
const result = await fetch(url, options);
if (result.status === 401) {
throw Error("Unauthorized");