diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index f0e477e..4d34a4a 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -1,15 +1,12 @@ import type { LoaderFunctionArgs } from '@remix-run/cloudflare'; import { json, useLoaderData } from '@remix-run/react'; import { Markdown } from '~/components'; -import { getFileContentWithCache } from '~/services/github.server'; import { parse } from '~/services/markdoc.server'; export async function loader({ context }: LoaderFunctionArgs) { - const content = await getFileContentWithCache(context, 'README.md'); - return json( { - content: parse(content), + content: '', }, { headers: { diff --git a/app/services/github.server.ts b/app/services/github.server.ts deleted file mode 100644 index bd23569..0000000 --- a/app/services/github.server.ts +++ /dev/null @@ -1,77 +0,0 @@ -import type { Endpoints } from '@octokit/types'; -import type { AppLoadContext } from '@remix-run/cloudflare'; - -export const metadata = { - repo: 'remix-cloudflare-template', - owner: 'edmundhung', -}; - -export function getHeaders(auth: string | undefined) { - const headers = new Headers({ - Accept: 'application/vnd.github+json', - 'User-Agent': 'Conform Guide', - }); - - if (auth) { - headers.set('Authorization', `Bearer ${auth}`); - } - - return headers; -} - -export async function getFileContent(options: { - auth?: string; - ref?: string; - path: string; - owner: string; - repo: string; -}): Promise { - const searchParams = new URLSearchParams(); - - if (options.ref) { - searchParams.set('ref', options.ref); - } - - const url = `https://api.github.com/repos/${options.owner}/${options.repo}/contents/${options.path}?${searchParams}`; - const resposne = await fetch(url, { - headers: getHeaders(options.auth), - }); - - if (resposne.status === 404) { - throw resposne; - } - - const file: Endpoints['GET /repos/{owner}/{repo}/contents/{path}']['response']['data'] = - await resposne.json(); - - if (Array.isArray(file) || file.type !== 'file') { - throw new Response('Not found', { status: 404 }); - } - - return atob(file.content); -} - -export async function getFileContentWithCache( - context: AppLoadContext, - path: string, -): Promise { - const key = `github/${path}`; - const cache = await context.env.cache.get(key); - - if (cache) { - return cache; - } - - const content = await getFileContent({ - auth: context.env.GITHUB_TOKEN, - owner: metadata.owner, - repo: metadata.repo, - path, - }); - - // Update the cache - // TODO: Use `waitUntil` to update the cache in the background - await context.env.cache.put(key, content, { expirationTtl: 60 * 60 }); - - return content; -}