diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts
index 9cb46cf6..e9b74872 100644
--- a/src/app/api/search/route.ts
+++ b/src/app/api/search/route.ts
@@ -14,7 +14,6 @@ export async function GET(request: NextRequest) {
["num", numResults],
["format", "json"],
);
- console.log(url);
const res = await fetch(url);
const data = await res.json();
diff --git a/src/app/api/source/route.ts b/src/app/api/source/route.ts
index 4b884590..d2a4d1a2 100644
--- a/src/app/api/source/route.ts
+++ b/src/app/api/source/route.ts
@@ -1,13 +1,11 @@
"use server";
-import { ErrorCode } from "@/lib/errorCodes";
-import { serviceError, missingQueryParam } from "@/lib/serviceError";
+import { missingQueryParam } from "@/lib/serviceError";
import { StatusCodes } from "http-status-codes";
import { NextRequest } from "next/server";
-import path from "path";
-import fs from "fs";
-import { GetSourceResponse, pathQueryParamName, repoQueryParamName } from "@/lib/types";
-
+import { GetSourceResponse, pathQueryParamName, repoQueryParamName, ZoektPrintResponse } from "@/lib/types";
+import { ZOEKT_WEBSERVER_URL } from "@/lib/environment";
+import { createPathWithQueryParams } from "@/lib/utils";
/**
* Returns the content of a source file at the given path.
@@ -28,44 +26,23 @@ export async function GET(request: NextRequest) {
return missingQueryParam(repoQueryParamName);
}
- // Get the contents of the path
- const repoPath = getRepoPath(repo);
- if (!repoPath) {
- return serviceError({
- statusCode: StatusCodes.NOT_FOUND,
- errorCode: ErrorCode.REPOSITORY_NOT_FOUND,
- message: `Could not find repository '${repo}'.`
- });
- }
+ const url = createPathWithQueryParams(
+ `${ZOEKT_WEBSERVER_URL}/print`,
+ ["f", filepath],
+ ["r", repo],
+ ["format", "json"],
+ );
- const fullPath = path.join(repoPath, filepath);
- if (!fs.existsSync(fullPath)) {
- return serviceError({
- statusCode: StatusCodes.NOT_FOUND,
- errorCode: ErrorCode.FILE_NOT_FOUND,
- message: `Could not find file '${filepath}' in repository '${repo}'.`
- });
- }
-
- // @todo : some error handling here would be nice
- const content = fs.readFileSync(fullPath, "utf8");
+ const res = await fetch(url);
+ const data = await res.json() as ZoektPrintResponse;
return Response.json(
{
- content,
+ content: data.Content,
+ encoding: data.Encoding,
} satisfies GetSourceResponse,
{
status: StatusCodes.OK
}
);
}
-
-// @todo : we will need to figure out a more sophisticated system for this..
-const getRepoPath = (repo: string): string | undefined => {
- switch (repo) {
- case "monorepo":
- return "/Users/brendan/monorepo"
- }
-
- return undefined;
-}
\ No newline at end of file
diff --git a/src/app/codePreview.tsx b/src/app/codePreview.tsx
index 98ae10da..28e11cc4 100644
--- a/src/app/codePreview.tsx
+++ b/src/app/codePreview.tsx
@@ -151,6 +151,7 @@ export const CodePreview = ({
extensions={extensions}
/>
+
)
diff --git a/src/app/page.tsx b/src/app/page.tsx
index 22c4002b..d28dd5e9 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -105,9 +105,14 @@ export default function Home() {
fetch(url)
.then(response => response.json())
.then((body: GetSourceResponse) => {
+ if (body.encoding !== "base64") {
+ throw new Error("Expected base64 encoding");
+ }
+
+ const content = atob(body.content);
setSelectedMatchIndex(0);
setPreviewFile({
- content: body.content,
+ content: content,
filepath: match.FileName,
matches: match.Matches,
});
diff --git a/src/lib/types.ts b/src/lib/types.ts
index a2532b30..3b8b9a25 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -5,6 +5,7 @@ export const repoQueryParamName = "repo";
export type GetSourceResponse = {
content: string;
+ encoding: string;
}
export interface ZoektMatch {
@@ -39,4 +40,9 @@ export interface ZoektSearchResponse {
result: ZoektResult,
}
+export interface ZoektPrintResponse {
+ Content: string,
+ Encoding: string,
+}
+
export type KeymapType = "default" | "vim";
\ No newline at end of file
diff --git a/vendor/zoekt b/vendor/zoekt
index 96970313..b0fd0b52 160000
--- a/vendor/zoekt
+++ b/vendor/zoekt
@@ -1 +1 @@
-Subproject commit 96970313fe9081d5e176341a85172287402d5f44
+Subproject commit b0fd0b52e8c6d01b5f13ba283602f291ac34b95a