···
68
+
constructor({ domain, ownerDid, repoName, branch }) {
69
+
this.domain = domain;
70
+
this.ownerDid = ownerDid;
71
+
this.repoName = repoName;
72
+
this.branch = branch;
75
+
async getBlob(filename) {
76
+
const url = `https://${this.domain}/${this.ownerDid}/${
78
+
}/blob/${this.branch}/${trimLeadingSlash(filename)}`;
79
+
const res = await fetch(url);
80
+
return await res.json();
83
+
async getRaw(filename) {
84
+
const url = `https://${this.domain}/${this.ownerDid}/${this.repoName}/raw/${
86
+
}/${trimLeadingSlash(filename)}`;
87
+
const res = await fetch(url, {
88
+
responseType: "arraybuffer",
90
+
const arrayBuffer = await res.arrayBuffer();
91
+
return Buffer.from(arrayBuffer);
···
configFilepath = "pages_config.yaml",
fileCacheExpirationSeconds = 10,
···
this.repoName = repoName;
this.configFilepath = configFilepath;
82
-
this.verbose = verbose;
this.fileCache = new FileCache({
expirationSeconds: fileCacheExpirationSeconds,
112
+
this.client = new KnotClient({
114
+
ownerDid: ownerDid,
115
+
repoName: repoName,
···
async getFileContent(filename) {
const cachedContent = this.fileCache.get(filename);
113
-
if (this.verbose) {
114
-
console.log(`Cache hit for ${filename}`);
118
-
// todo error handling?
119
-
const url = `https://${this.domain}/${this.ownerDid}/${
121
-
}/blob/${this.branch}/${trimLeadingSlash(filename)}`;
122
-
if (this.verbose) {
123
-
console.log(`Fetching ${url}`);
147
+
let content = null;
148
+
const blob = await this.client.getBlob(filename);
149
+
if (blob.is_binary) {
150
+
content = await this.client.getRaw(filename);
152
+
content = blob.contents;
125
-
const res = await fetch(url, {
127
-
Accept: "application/json",
130
-
const blob = await res.json();
131
-
const content = blob.contents;
this.fileCache.set(filename, content);