fix: UTF-8解码修复中文乱码
This commit is contained in:
parent
3eefc02089
commit
bacd79cb0e
|
|
@ -1,7 +1,8 @@
|
||||||
// HoloLake Era · V0.1 · Gitea API 数据服务
|
// HoloLake Era · V0.1 · Gitea API 数据服务
|
||||||
// 连接 guanghutansuohe.com 的 yeye 仓库作为事实源
|
// 连接 guanghutansuohe.com 的 yeye 仓库作为事实源
|
||||||
|
|
||||||
const BASE = "https://guanghutansuohe.com/code/api/v1/repos/bingshuo/yeye/contents";
|
// 通过 Vite 代理访问 Gitea API(避免 CORS)
|
||||||
|
const BASE = "/gitea-api/repos/bingshuo/yeye/contents";
|
||||||
|
|
||||||
async function fetchJson(url: string): Promise<any> {
|
async function fetchJson(url: string): Promise<any> {
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
|
|
@ -12,8 +13,8 @@ async function fetchJson(url: string): Promise<any> {
|
||||||
// 读取文件内容(API返回base64编码)
|
// 读取文件内容(API返回base64编码)
|
||||||
async function readFile(path: string): Promise<string> {
|
async function readFile(path: string): Promise<string> {
|
||||||
const data = await fetchJson(`${BASE}/${path}?ref=main`);
|
const data = await fetchJson(`${BASE}/${path}?ref=main`);
|
||||||
const decoded = atob(data.content);
|
const bytes = Uint8Array.from(atob(data.content), (c: string) => c.charCodeAt(0));
|
||||||
return decoded;
|
return new TextDecoder("utf-8").decode(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 列出目录
|
// 列出目录
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue