From 9bf40a0aa6633b8fa45b87b1f0439144ef574df9 Mon Sep 17 00:00:00 2001 From: Alexej Wolff Date: Thu, 7 May 2026 01:02:55 +0200 Subject: [PATCH] fix: explicit UTF-8 charset everywhere --- server/index.js | 10 +++++----- src/services/deepseek.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/index.js b/server/index.js index 366e186..73f3a25 100644 --- a/server/index.js +++ b/server/index.js @@ -1217,7 +1217,7 @@ app.post("/api/deepseek/chat", requireAuth, async (req, res) => { const response = await fetch(DEEPSEEK_API_URL, { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json; charset=utf-8", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ @@ -1279,7 +1279,7 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => { const response = await fetch(DEEPSEEK_API_URL, { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json; charset=utf-8", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ @@ -1299,13 +1299,13 @@ app.post("/api/deepseek/chat/stream", requireAuth, async (req, res) => { } // 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("Connection", "keep-alive"); // Pipe the stream const reader = response.body.getReader(); - const decoder = new TextDecoder(); + const decoder = new TextDecoder("utf-8"); const pump = async () => { try { @@ -1368,7 +1368,7 @@ app.post("/api/deepseek/translate", requireAuth, async (req, res) => { const response = await fetch(DEEPSEEK_API_URL, { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json; charset=utf-8", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ diff --git a/src/services/deepseek.ts b/src/services/deepseek.ts index b973906..c3da97d 100644 --- a/src/services/deepseek.ts +++ b/src/services/deepseek.ts @@ -42,7 +42,7 @@ export async function sendMessage( const response = await fetch(`${API_BASE}/api/deepseek/chat`, { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json; charset=utf-8", }, credentials: "include", body: JSON.stringify({ @@ -82,7 +82,7 @@ export async function sendMessageStream( const response = await fetch(`${API_BASE}/api/deepseek/chat/stream`, { method: "POST", headers: { - "Content-Type": "application/json", + "Content-Type": "application/json; charset=utf-8", }, credentials: "include", body: JSON.stringify({ @@ -110,7 +110,7 @@ export async function sendMessageStream( const reader = response.body?.getReader(); if (!reader) throw new Error("No response body"); - const decoder = new TextDecoder(); + const decoder = new TextDecoder("utf-8"); let fullContent = ""; let buffer = ""; // Buffer for incomplete lines @@ -120,7 +120,7 @@ export async function sendMessageStream( // Append new data to buffer buffer += decoder.decode(value, { stream: true }); - + // Process complete lines only const lines = buffer.split("\n"); // Keep last incomplete line in buffer @@ -129,7 +129,7 @@ export async function sendMessageStream( for (const line of lines) { const trimmed = line.trim(); if (!trimmed || !trimmed.startsWith("data: ")) continue; - + const data = trimmed.slice(6); if (data === "[DONE]") continue;