Browse Source
instead of just github. unfortunately most servers have CORS enabled so a proxy is neededmaster
5 changed files with 201 additions and 79 deletions
@ -1,28 +0,0 @@
@@ -1,28 +0,0 @@
|
||||
import { extractGithubDetails } from '$lib/components/repo/utils' |
||||
|
||||
export const GET = async ({ params }: { params: { clone: string } }) => { |
||||
const github_details = extractGithubDetails(decodeURIComponent(params.clone)) |
||||
if (github_details) { |
||||
const res = await fetch( |
||||
`https://raw.githubusercontent.com/${github_details.org}/${github_details.repo_name}/HEAD/README.md` |
||||
) |
||||
const text = await res.text() |
||||
|
||||
return new Response(text) |
||||
} else { |
||||
// options:
|
||||
// * add support for different git server implementations that serve raw
|
||||
// files and cycle through the urls until we find the readme
|
||||
// * add a worker that can use 'git archive' to get specific files
|
||||
// * unfortunately the two options that can easily embeded within this
|
||||
// sveltekit backend (wasm-git and isomorphicgit) don't support the
|
||||
// 'archive' command
|
||||
// https://github.com/petersalomonsen/wasm-git/
|
||||
// https://github.com/isomorphic-git
|
||||
// * 'git clone' is too expensive for retrieving single files. even when
|
||||
// done using treeless or blobless flags. see:
|
||||
// https://noise.getoto.net/2020/12/21/get-up-to-speed-with-partial-clone-and-shallow-clone/
|
||||
|
||||
return new Response(null) |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
import { error } from '@sveltejs/kit' |
||||
|
||||
export const GET = async ({ params }: { params: { readme_url: string } }) => { |
||||
// prevent abuse of the proxy by ensuring the url contains 'readme.md'
|
||||
if ( |
||||
!( |
||||
params.readme_url.includes('readme.md') || |
||||
params.readme_url.includes('README.md') |
||||
) |
||||
) |
||||
return new Response(null) |
||||
|
||||
let text: string | undefined |
||||
try { |
||||
const res = await fetch(params.readme_url, { |
||||
signal: AbortSignal.timeout(5000), |
||||
}) |
||||
if (res.ok) { |
||||
text = await res.text() |
||||
} else { |
||||
return error(res.status, res.statusText) |
||||
} |
||||
} catch { |
||||
return error(408, 'timeout') |
||||
} |
||||
return new Response(text || null) |
||||
|
||||
// `https://raw.githubusercontent.com/${github_details.org}/${github_details.repo_name}/HEAD/README.md`
|
||||
// alternative approaches:
|
||||
// * add a worker that can use 'git archive' to get specific files
|
||||
// * unfortunately the two options that can easily embeded within this
|
||||
// sveltekit backend (wasm-git and isomorphicgit) don't support the
|
||||
// 'archive' command
|
||||
// https://github.com/petersalomonsen/wasm-git/
|
||||
// https://github.com/isomorphic-git
|
||||
// * 'git clone' is too expensive for retrieving single files. even when
|
||||
// done using treeless or blobless flags. see:
|
||||
// https://noise.getoto.net/2020/12/21/get-up-to-speed-with-partial-clone-and-shallow-clone/
|
||||
} |
||||
Loading…
Reference in new issue