Browse Source

turn off readme proxy

to reducing render function invocations per last commit
master
DanConwayDev 2 years ago
parent
commit
fc8c68eb6d
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 15
      src/lib/stores/repo.ts
  2. 44
      src/routes/git_proxy/readme/[readme_url]/+server.ts

15
src/lib/stores/repo.ts

@ -36,7 +36,7 @@ let selected_unsubscriber: Unsubscriber @@ -36,7 +36,7 @@ let selected_unsubscriber: Unsubscriber
export const ensureSelectedRepoCollection = (
a: string,
naddr_relays: string[] | undefined = undefined,
naddr_relays: string[] | undefined = undefined
): Writable<RepoCollection> => {
if (selected_repo_a !== a) {
let loading = true
@ -106,11 +106,16 @@ const ensureRepoReadme = async (clone: string[], a: string): Promise<void> => { @@ -106,11 +106,16 @@ const ensureRepoReadme = async (clone: string[], a: string): Promise<void> => {
]
for (let i = 0; i < readme_urls.length; i++) {
try {
// temporarily disable using proxy
if (!readme_urls[i].includes('raw.githubusercontent.com')) {
continue
}
const res = await fetch(
readme_urls[i].includes('raw.githubusercontent.com')
? readme_urls[i]
: // use proxy as most servers produce a CORS error
`/git_proxy/readme/${encodeURIComponent(readme_urls[i])}`
readme_urls[i]
// readme_urls[i].includes('raw.githubusercontent.com')
// ? readme_urls[i]
// : // use proxy as most servers produce a CORS error
// `/git_proxy/readme/${encodeURIComponent(readme_urls[i])}`
)
if (res.ok) {
text = await res.text()

44
src/routes/git_proxy/readme/[readme_url]/+server.ts

@ -1,44 +0,0 @@ @@ -1,44 +0,0 @@
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/
// files can be listed at:
// * gitea / forgejo https://codeberg.org/api/v1/repos/DanConwayDev/ngit-cli/git/trees/HEAD
// * github - https://api.github.com/repos/DanConwayDev/ngit-cli/git/trees/HEAD?recursive=1
// * gitlab - tbc
// * gogs - needs testing - https://github.com/gogs/docs-api/
}
Loading…
Cancel
Save