From 1d4bc03aac4c228e1c141d0552e0f3c2bdbffd39 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Sun, 23 Feb 2025 16:42:56 +0100 Subject: [PATCH] Change GithubClient.getBlob use the sha instead of the URL --- src/github/client.ts | 8 ++++---- src/sync-manager.ts | 6 ++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/github/client.ts b/src/github/client.ts index 5e6017c..accf0f2 100644 --- a/src/github/client.ts +++ b/src/github/client.ts @@ -144,12 +144,12 @@ export default class GithubClient { } /** - * Gets a blob from a blob url - * @param url blob url + * Gets a blob from its sha + * @param url blob sha */ - async getBlob(url: string): Promise { + async getBlob(sha: string): Promise { const res = await requestUrl({ - url: url, + url: `https://api.github.com/repos/${this.settings.githubOwner}/${this.settings.githubRepo}/git/blobs/${sha}`, headers: this.headers(), throw: false, }); diff --git a/src/sync-manager.ts b/src/sync-manager.ts index a639ee9..00d1256 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -287,7 +287,7 @@ export default class SyncManager { throw new Error("Remote manifest is missing"); } - const blob = await this.client.getBlob(manifest.url); + const blob = await this.client.getBlob(manifest.sha); const remoteMetadata: Metadata = JSON.parse(atob(blob.content)); const conflicts = this.findConflicts( @@ -603,14 +603,12 @@ export default class SyncManager { } async downloadFile(file: GetTreeResponseItem, lastModified: number) { - const url = file.url; const fileMetadata = this.metadataStore.data.files[file.path]; if (fileMetadata && fileMetadata.sha === file.sha) { // File already exists and has the same SHA, no need to download it again. return; } - - const blob = await this.client.getBlob(url); + const blob = await this.client.getBlob(file.sha); const normalizedPath = normalizePath(file.path); const fileFolder = normalizePath( normalizedPath.split("/").slice(0, -1).join("/"),