Skip to content

Commit f74e9de

Browse files
committed
Fix: Use raw.githubusercontent.com for getFile instead of Contents API
The GitHub Contents API with query params was returning 404. raw.githubusercontent.com works better and has no rate limits.
1 parent 29d5529 commit f74e9de

1 file changed

Lines changed: 4 additions & 26 deletions

File tree

src/storage/repo/repo-client.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,33 +103,11 @@ export class RepoStorageBackend implements StorageBackend {
103103

104104
public async getFile(path: string): Promise<string | null> {
105105
const fullPath = `${SYNC_DIR}/${path}`;
106-
// Add cache-bust to avoid stale GitHub API responses
106+
const branch = await this.getBranch();
107+
// Use raw.githubusercontent.com with cache-bust to avoid stale CDN responses
107108
const cacheBust = Date.now();
108-
const res = await this.fetchAllowNotFound(`/contents/${fullPath}?cb=${String(cacheBust)}`);
109-
if (!res?.ok) return null;
110-
111-
const data = (await res.json()) as ContentFile;
112-
113-
// For files >1MB, GitHub returns empty content and provides download_url
114-
if (!data.content && data.size > 1000000) {
115-
const branch = await this.getBranch();
116-
// Add cache-bust to avoid stale CDN responses
117-
const downloadUrl = `https://raw.githubusercontent.com/${this.owner}/${this.repo}/${branch}/${fullPath}?cb=${String(cacheBust)}`;
118-
const downloadRes = await fetchWithRetry(
119-
downloadUrl,
120-
{
121-
headers: { Authorization: `Bearer ${this.token}` },
122-
},
123-
this.maxRetries,
124-
this.retryDelayMs
125-
);
126-
127-
if (!downloadRes.ok) return null;
128-
return await downloadRes.text();
129-
}
130-
131-
if (!data.content) return null;
132-
return Buffer.from(data.content, 'base64').toString('utf-8');
109+
const url = `https://raw.githubusercontent.com/${this.owner}/${this.repo}/${branch}/${fullPath}?cb=${String(cacheBust)}`;
110+
return await this.fetchRawFile(url);
133111
}
134112

135113
public async updateFiles(files: Record<string, string | null>): Promise<void> {

0 commit comments

Comments
 (0)