Static site hosting via tangled
1import { trimLeadingSlash } from "./helpers.js";
2
3export class KnotClient {
4 constructor({ domain, ownerDid, repoName, branch }) {
5 this.domain = domain;
6 this.ownerDid = ownerDid;
7 this.repoName = repoName;
8 this.branch = branch;
9 }
10
11 async getBlob(filename) {
12 const url = `https://${this.domain}/${this.ownerDid}/${
13 this.repoName
14 }/blob/${this.branch}/${trimLeadingSlash(filename)}`;
15 console.log(`[KNOT CLIENT]: GET ${url}`);
16 const res = await fetch(url);
17 return await res.json();
18 }
19
20 async getRaw(filename) {
21 const url = `https://${this.domain}/${this.ownerDid}/${this.repoName}/raw/${
22 this.branch
23 }/${trimLeadingSlash(filename)}`;
24 console.log(`[KNOT CLIENT]: GET ${url}`);
25 const res = await fetch(url, {
26 responseType: "arraybuffer",
27 });
28 const arrayBuffer = await res.arrayBuffer();
29 return Buffer.from(arrayBuffer);
30 }
31}