From 0dfa9814ec998487c4f76e3418e0a232dbcceb7d Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Thu, 22 Jan 2026 18:35:27 -0500 Subject: Add blob view for displaying file contents --- src/scraper.ts | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'src/scraper.ts') diff --git a/src/scraper.ts b/src/scraper.ts index add03b2..fa8d655 100644 --- a/src/scraper.ts +++ b/src/scraper.ts @@ -15,6 +15,20 @@ export interface GitHubTree { }; } +export interface GitHubBlob { + path: string; + branch: string; + content: string; + rawContent: string; + language: string | null; + size: number; + repo: { + name: string; + owner: string; + isPublic: boolean; + }; +} + export async function getGitHubTree( owner: string, repo: string, @@ -89,3 +103,66 @@ export async function getGitHubTree( }, }; } + +export async function getGitHubBlob( + owner: string, + repo: string, + branch: string, + path: string, +): Promise { + const url = `https://github.com/${owner}/${repo}/blob/${branch}/${path}`; + + const response = await fetch(url, { + headers: { + "User-Agent": + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36", + Accept: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", + "Accept-Language": "en-US,en;q=0.5", + }, + }); + const html = await response.text(); + + // GitHub embeds file data in a JSON script tag + let payload; + + const match = html.match( + /