mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
fix: fix javascript btoa function can not handle Unicode strings issue (#38)
This commit is contained in:
parent
e4b261a7f3
commit
825a5aa7f5
3 changed files with 11 additions and 4 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { fetchFileSource } from "@/app/api/(client)/client";
|
import { fetchFileSource } from "@/app/api/(client)/client";
|
||||||
import { getCodeHostFilePreviewLink } from "@/lib/utils";
|
import { getCodeHostFilePreviewLink, base64Decode } from "@/lib/utils";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { CodePreview, CodePreviewFile } from "./codePreview";
|
import { CodePreview, CodePreviewFile } from "./codePreview";
|
||||||
import { SearchResultFile } from "@/lib/types";
|
import { SearchResultFile } from "@/lib/types";
|
||||||
|
|
@ -32,7 +32,7 @@ export const CodePreviewPanel = ({
|
||||||
// @todo : refector this to use the templates provided by zoekt.
|
// @todo : refector this to use the templates provided by zoekt.
|
||||||
const link = getCodeHostFilePreviewLink(fileMatch.Repository, fileMatch.FileName)
|
const link = getCodeHostFilePreviewLink(fileMatch.Repository, fileMatch.FileName)
|
||||||
|
|
||||||
const decodedSource = atob(source);
|
const decodedSource = base64Decode(source);
|
||||||
|
|
||||||
// Filter out filename matches
|
// Filter out filename matches
|
||||||
const filteredMatches = fileMatch.ChunkMatches.filter((match) => {
|
const filteredMatches = fileMatch.ChunkMatches.filter((match) => {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { CodePreview } from "./codePreview";
|
import { CodePreview } from "./codePreview";
|
||||||
import { SearchResultFile, SearchResultFileMatch } from "@/lib/types";
|
import { SearchResultFile, SearchResultFileMatch } from "@/lib/types";
|
||||||
|
import { base64Decode } from "@/lib/utils";
|
||||||
|
|
||||||
|
|
||||||
interface FileMatchProps {
|
interface FileMatchProps {
|
||||||
|
|
@ -17,7 +18,7 @@ export const FileMatch = ({
|
||||||
onOpen,
|
onOpen,
|
||||||
}: FileMatchProps) => {
|
}: FileMatchProps) => {
|
||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
return atob(match.Content);
|
return base64Decode(match.Content);
|
||||||
}, [match.Content]);
|
}, [match.Content]);
|
||||||
|
|
||||||
// If it's just the title, don't show a code preview
|
// If it's just the title, don't show a code preview
|
||||||
|
|
|
||||||
|
|
@ -96,3 +96,9 @@ export const getEnvBoolean = (env: string | undefined, defaultValue: boolean) =>
|
||||||
}
|
}
|
||||||
return env === 'true' || env === '1';
|
return env === 'true' || env === '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
|
||||||
|
export const base64Decode = (base64: string): string => {
|
||||||
|
const binString = atob(base64);
|
||||||
|
return Buffer.from(Uint8Array.from(binString, (m) => m.codePointAt(0)!).buffer).toString();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue