···
···
configFilepath = "pages_config.yaml",
fileCacheExpirationSeconds = 10,
···
this.repoName = repoName;
this.configFilepath = configFilepath;
-
this.verbose = verbose;
this.fileCache = new FileCache({
expirationSeconds: fileCacheExpirationSeconds,
···
async getFileContent(filename) {
const cachedContent = this.fileCache.get(filename);
-
console.log(`Cache hit for ${filename}`);
-
// todo error handling?
-
const url = `https://${this.domain}/${this.ownerDid}/${
-
}/blob/${this.branch}/${trimLeadingSlash(filename)}`;
-
console.log(`Fetching ${url}`);
-
const res = await fetch(url, {
-
Accept: "application/json",
-
const blob = await res.json();
-
const content = blob.contents;
this.fileCache.set(filename, content);
···
+
constructor({ domain, ownerDid, repoName, branch }) {
+
this.ownerDid = ownerDid;
+
this.repoName = repoName;
+
async getBlob(filename) {
+
const url = `https://${this.domain}/${this.ownerDid}/${
+
}/blob/${this.branch}/${trimLeadingSlash(filename)}`;
+
const res = await fetch(url);
+
return await res.json();
+
async getRaw(filename) {
+
const url = `https://${this.domain}/${this.ownerDid}/${this.repoName}/raw/${
+
}/${trimLeadingSlash(filename)}`;
+
const res = await fetch(url, {
+
responseType: "arraybuffer",
+
const arrayBuffer = await res.arrayBuffer();
+
return Buffer.from(arrayBuffer);
···
configFilepath = "pages_config.yaml",
fileCacheExpirationSeconds = 10,
···
this.repoName = repoName;
this.configFilepath = configFilepath;
this.fileCache = new FileCache({
expirationSeconds: fileCacheExpirationSeconds,
+
this.client = new KnotClient({
···
async getFileContent(filename) {
const cachedContent = this.fileCache.get(filename);
+
const blob = await this.client.getBlob(filename);
+
content = await this.client.getRaw(filename);
+
content = blob.contents;
this.fileCache.set(filename, content);