-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/routes/(opengrok-compat)/diff/[project]/[...file]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { escapeRegExp } from "$lib/regexp"; | ||
import { projectToRepo } from "$lib/server/opengrok-compat"; | ||
import { listRepositories } from "$lib/server/zoekt-list-repositories"; | ||
import { error, redirect } from "@sveltejs/kit"; | ||
|
||
export const load: import("./$types").PageServerLoad = async ({ | ||
url, | ||
params: { file, project }, | ||
parent, | ||
setHeaders, | ||
fetch, | ||
}) => { | ||
if (!file) { | ||
throw error(404); | ||
} | ||
const revision = url.searchParams.get("r"); | ||
const convertedRepo = projectToRepo.get(project); | ||
|
||
const result = await listRepositories( | ||
{ | ||
query: `repo:^${escapeRegExp(convertedRepo ?? project)}$`, | ||
}, | ||
fetch | ||
); | ||
if (result.kind === "error") { | ||
throw new Error(`Failed to list repositories: ${result.error}`); | ||
} | ||
|
||
const repo = result.results.repositories[0]; | ||
const fileUrl = repo?.fileUrlTemplate | ||
.replaceAll("{{.Version}}", revision ?? repo.branches[0].name) | ||
.replaceAll("{{.Path}}", file); | ||
|
||
setHeaders({ | ||
"cache-control": "no-store,must-revalidate", | ||
}); | ||
|
||
if (fileUrl && (await parent()).preferences.openGrokInstantRedirect) { | ||
throw redirect(301, fileUrl); | ||
} | ||
|
||
return { file, fileUrl }; | ||
}; |
27 changes: 27 additions & 0 deletions
27
src/routes/(opengrok-compat)/diff/[project]/[...file]/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script lang="ts"> | ||
import ExampleQuery from "$lib/example-query.svelte"; | ||
import Link from "$lib/link.svelte"; | ||
import { escapeRegExp } from "$lib/regexp"; | ||
export let data: import("./$types").PageData; | ||
</script> | ||
|
||
<section class="space-y-2 pt-2"> | ||
<h2 class="text-2xl text-center">Diff viewer</h2> | ||
<p> | ||
OpenGrok's diff viewer that was previously available at this URL is | ||
unfortunately not supported in neogrok. | ||
</p> | ||
{#if data.fileUrl} | ||
<p> | ||
That being said, we've been able to produce a URL to view the file on its | ||
home site. Head on over: <Link to={data.fileUrl}>{data.fileUrl}</Link>. | ||
</p> | ||
{:else} | ||
<p> | ||
Even more unfortunately, we've not been able to produce a URL to view the | ||
file somewhere else. You can try searching for it and going from there: | ||
<ExampleQuery query={`file:^${escapeRegExp(data.file)}$`} />. | ||
</p> | ||
{/if} | ||
</section> |