MCPcopy Create free account
hub / github.com/idosal/git-mcp / fetchFileFromR2

Function fetchFileFromR2

src/api/utils/r2.ts:1–23  ·  view source on GitHub ↗
(
  owner: string,
  repo: string,
  filename: string,
  env: CloudflareEnvironment,
)

Source from the content-addressed store, hash-verified

1export async function fetchFileFromR2(
2 owner: string,
3 repo: string,
4 filename: string,
5 env: CloudflareEnvironment,
6): Promise<string | null> {
7 if (owner && repo && env.DOCS_BUCKET) {
8 try {
9 const obj = await env.DOCS_BUCKET.get(
10 owner + "/" + repo + "/" + filename,
11 );
12 if (obj) {
13 return await new Response(obj.body).text();
14 } else {
15 console.log("Didn't find docs file in r2");
16 }
17 } catch (error) {
18 console.error("Failed to fetch docs file from r2", error);
19 }
20 }
21
22 return null;
23}

Callers 1

fetchDocumentationFunction · 0.85

Calls 4

logMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected