fix(blob): use TextDecoder for proper UTF-8 decoding

- atob() returns Latin-1 binary string, not UTF-8
- Chinese characters decoded incorrectly causing mojibake
- Use TextDecoder("utf-8") with Uint8Array for correct handling
This commit is contained in:
ZhenYi 2026-04-28 09:42:52 +08:00
parent 21d0d1eae6
commit da2853d0ec

View File

@ -115,9 +115,11 @@ export const FileBrowser = ({ branch, initialPath = "" }: FileBrowserProps) => {
});
const data = resp.data?.data;
if (!data) return null;
// Content is base64 encoded
// Content is base64 encoded, use TextDecoder for proper UTF-8 handling
try {
return atob(data.content);
const binary = atob(data.content);
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
} catch {
return data.content;
}