fix: explicit UTF-8 charset everywhere

This commit is contained in:
Alexej Wolff
2026-05-07 01:02:55 +02:00
parent 51964edff7
commit 9bf40a0aa6
2 changed files with 10 additions and 10 deletions
+5 -5
View File
@@ -1217,7 +1217,7 @@ app.post("/api/deepseek/chat", requireAuth, async (req, res) => {
const response = await fetch(DEEPSEEK_API_URL, { const response = await fetch(DEEPSEEK_API_URL, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json; charset=utf-8",
Authorization: `Bearer ${apiKey}`, Authorization: `Bearer ${apiKey}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
@@ -1279,7 +1279,7 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => {
const response = await fetch(DEEPSEEK_API_URL, { const response = await fetch(DEEPSEEK_API_URL, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json; charset=utf-8",
Authorization: `Bearer ${apiKey}`, Authorization: `Bearer ${apiKey}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
@@ -1299,13 +1299,13 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => {
} }
// Set headers for SSE // Set headers for SSE
res.setHeader("Content-Type", "text/event-stream"); res.setHeader("Content-Type", "text/event-stream; charset=utf-8");
res.setHeader("Cache-Control", "no-cache"); res.setHeader("Cache-Control", "no-cache");
res.setHeader("Connection", "keep-alive"); res.setHeader("Connection", "keep-alive");
// Pipe the stream // Pipe the stream
const reader = response.body.getReader(); const reader = response.body.getReader();
const decoder = new TextDecoder(); const decoder = new TextDecoder("utf-8");
const pump = async () => { const pump = async () => {
try { try {
@@ -1368,7 +1368,7 @@ app.post("/api/deepseek/translate", requireAuth, async (req, res) => {
const response = await fetch(DEEPSEEK_API_URL, { const response = await fetch(DEEPSEEK_API_URL, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json; charset=utf-8",
Authorization: `Bearer ${apiKey}`, Authorization: `Bearer ${apiKey}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
+5 -5
View File
@@ -42,7 +42,7 @@ export async function sendMessage(
const response = await fetch(`${API_BASE}/api/deepseek/chat`, { const response = await fetch(`${API_BASE}/api/deepseek/chat`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json; charset=utf-8",
}, },
credentials: "include", credentials: "include",
body: JSON.stringify({ body: JSON.stringify({
@@ -82,7 +82,7 @@ export async function sendMessageStream(
const response = await fetch(`${API_BASE}/api/deepseek/chat/stream`, { const response = await fetch(`${API_BASE}/api/deepseek/chat/stream`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json; charset=utf-8",
}, },
credentials: "include", credentials: "include",
body: JSON.stringify({ body: JSON.stringify({
@@ -110,7 +110,7 @@ export async function sendMessageStream(
const reader = response.body?.getReader(); const reader = response.body?.getReader();
if (!reader) throw new Error("No response body"); if (!reader) throw new Error("No response body");
const decoder = new TextDecoder(); const decoder = new TextDecoder("utf-8");
let fullContent = ""; let fullContent = "";
let buffer = ""; // Buffer for incomplete lines let buffer = ""; // Buffer for incomplete lines
@@ -120,7 +120,7 @@ export async function sendMessageStream(
// Append new data to buffer // Append new data to buffer
buffer += decoder.decode(value, { stream: true }); buffer += decoder.decode(value, { stream: true });
// Process complete lines only // Process complete lines only
const lines = buffer.split("\n"); const lines = buffer.split("\n");
// Keep last incomplete line in buffer // Keep last incomplete line in buffer
@@ -129,7 +129,7 @@ export async function sendMessageStream(
for (const line of lines) { for (const line of lines) {
const trimmed = line.trim(); const trimmed = line.trim();
if (!trimmed || !trimmed.startsWith("data: ")) continue; if (!trimmed || !trimmed.startsWith("data: ")) continue;
const data = trimmed.slice(6); const data = trimmed.slice(6);
if (data === "[DONE]") continue; if (data === "[DONE]") continue;