Handle char encoding on logs more correctly

This commit is contained in:
Yukino Song
2025-04-01 21:27:30 +08:00
parent a31828dd9c
commit e271592408
5 changed files with 75 additions and 6 deletions

View File

@@ -183,10 +183,23 @@
methods: {
refreshLogs() {
fetch("./api/logs", { credentials: 'include' })
.then((r) => r.text())
.then((r) => {
this.logs = r;
});
.then(response => {
// Retrieve the Content-Type header
const contentType = response.headers.get("Content-Type") || "";
// Attempt to extract charset from the header
const charsetMatch = contentType.match(/charset=([^;]+)/i);
const charset = charsetMatch ? charsetMatch[1].trim() : "utf-8";
// Read response as an ArrayBuffer and decode it with the correct charset
return response.arrayBuffer().then(buffer => {
const decoder = new TextDecoder(charset);
return decoder.decode(buffer);
});
})
.then(text => {
this.logs = text;
})
.catch(error => console.error("Error fetching logs:", error));
},
closeApp() {
this.closeAppPressed = true;