import { trimLeadingSlash } from "./helpers.js"; export class KnotClient { constructor({ domain, ownerDid, repoName, branch }) { this.domain = domain; this.ownerDid = ownerDid; this.repoName = repoName; this.branch = branch; } async getBlob(filename) { const params = new URLSearchParams({ repo: `${this.ownerDid}/${this.repoName}`, path: trimLeadingSlash(filename), ref: this.branch, }); const url = `https://${this.domain}/xrpc/sh.tangled.repo.blob?${params}`; console.log(`[KNOT CLIENT]: GET ${url}`); const res = await fetch(url); return await res.json(); } async getRaw(filename) { const params = new URLSearchParams({ repo: `${this.ownerDid}/${this.repoName}`, path: trimLeadingSlash(filename), ref: this.branch, raw: "true", }); const url = `https://${this.domain}/xrpc/sh.tangled.repo.blob?${params}`; console.log(`[KNOT CLIENT]: GET ${url}`); const res = await fetch(url, { responseType: "arraybuffer", }); const arrayBuffer = await res.arrayBuffer(); return Buffer.from(arrayBuffer); } }