Update _worker.js

解决base64解码后中文编码异常的问题
This commit is contained in:
CMLiussss
2024-03-19 15:03:33 +08:00
committed by GitHub
parent ef4386f1b8
commit 666ac3e3c2

View File

@@ -107,7 +107,9 @@ export default {
for (const response of responses) {
if (response.ok) {
const content = await response.text();
req_data += atob(content) + '\n';
//console.log(content);
req_data += base64Decode(content) + '\n';
//console.log(req_data);
}
}
} catch (error) {
@@ -124,6 +126,7 @@ export default {
//console.log(result);
const base64Data = btoa(result);
//console.log(base64Data);
return new Response(base64Data ,{
headers: {
"content-type": "text/plain; charset=utf-8",
@@ -156,3 +159,10 @@ async function sendMessage(type, ip, add_data = "") {
});
}
}
// 将 base64 编码的字符串转换为 utf-8 编码的字符
function base64Decode(str) {
const bytes = new Uint8Array(atob(str).split('').map(c => c.charCodeAt(0)));
const decoder = new TextDecoder('utf-8');
return decoder.decode(bytes);
}