From 32e765c3a09368d9bf0cfa3d7d6c38fe47431fcc Mon Sep 17 00:00:00 2001 From: HuiNeng6 <3650306360@qq.com> Date: Fri, 27 Mar 2026 12:46:51 +0800 Subject: [PATCH] feat: Add Export as .txt file option - Update backend exportController to handle txt format - Add txt format with text/plain content type - Update frontend handleExport to support txt format - Add Export TXT button in header Fixes: #5 --- backend/src/controllers/exportController.ts | 6 +++++- frontend/src/App.tsx | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/src/controllers/exportController.ts b/backend/src/controllers/exportController.ts index 8ff1869..5c0a89d 100644 --- a/backend/src/controllers/exportController.ts +++ b/backend/src/controllers/exportController.ts @@ -21,8 +21,12 @@ export const handleExport = async (req: Request, res: Response) => { buffer = await generateDocxBuffer(text); contentType = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; extension = 'docx'; + } else if (format === 'txt') { + buffer = Buffer.from(text, 'utf-8'); + contentType = 'text/plain'; + extension = 'txt'; } else { - return res.status(400).json({ error: 'Invalid export format. Use "pdf" or "docx".' }); + return res.status(400).json({ error: 'Invalid export format. Use "pdf", "docx", or "txt".' }); } const downloadName = `${fileName || 'humanized_text'}.${extension}`; diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7600cae..ebbf28d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -177,7 +177,7 @@ function App() { setTimeout(() => setCopySuccess(false), 2000); }; - const handleExport = async (format: 'pdf' | 'docx') => { + const handleExport = async (format: 'pdf' | 'docx' | 'txt') => { if (!humanizedText) { alert('Please generate content first before exporting.'); return; @@ -400,11 +400,18 @@ function App() { +