Skip to content

feat: Add Export as .txt file option#8

Open
HuiNeng6 wants to merge 1 commit intoSappymukherjee214:mainfrom
HuiNeng6:feat/export-txt
Open

feat: Add Export as .txt file option#8
HuiNeng6 wants to merge 1 commit intoSappymukherjee214:mainfrom
HuiNeng6:feat/export-txt

Conversation

@HuiNeng6
Copy link
Copy Markdown

Add TXT export option alongside PDF and DOCX.

Backend: Added txt format handling with text/plain content type
Frontend: Added Export TXT button and updated handleExport

Fixes: #5

- 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: Sappymukherjee214#5
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add TXT export format alongside PDF and DOCX

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add TXT export format support to backend with text/plain content type
• Update frontend handleExport function to accept txt format parameter
• Add Export TXT button in header with consistent styling
• Update error message to reflect all supported export formats
Diagram
flowchart LR
  User["User clicks Export TXT"] -->|txt format| Frontend["Frontend handleExport"]
  Frontend -->|POST /api/export| Backend["Backend exportController"]
  Backend -->|Buffer.from utf-8| TxtHandler["TXT Handler"]
  TxtHandler -->|text/plain| Download["Download .txt file"]
Loading

Grey Divider

File Changes

1. backend/src/controllers/exportController.ts ✨ Enhancement +5/-1

Add TXT export format handling to backend

• Added txt format handling branch with Buffer.from for UTF-8 encoding
• Set content type to text/plain for txt exports
• Updated error message to include txt as valid export format

backend/src/controllers/exportController.ts


2. frontend/src/App.tsx ✨ Enhancement +9/-2

Add TXT export button and update export handler

• Updated handleExport function signature to accept txt format type
• Added Export TXT button with FileText icon and consistent styling
• Added border-r class to DOCX button for visual consistency
• TXT button calls handleExport with txt format parameter

frontend/src/App.tsx


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review bot commented Mar 27, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Remediation recommended

1. TXT charset not specified 🐞 Bug ✓ Correctness
Description
handleExport encodes TXT as UTF-8 bytes but responds with Content-Type: text/plain (no charset),
and the frontend re-wraps the response blob without preserving the response MIME type. This can
cause clients to misinterpret text encoding (especially for non-ASCII) and results in a Blob with an
empty/incorrect type.
Code

backend/src/controllers/exportController.ts[R24-27]

+        } else if (format === 'txt') {
+            buffer = Buffer.from(text, 'utf-8');
+            contentType = 'text/plain';
+            extension = 'txt';
Evidence
The backend explicitly creates a UTF-8 buffer but does not advertise UTF-8 in the Content-Type
header; the frontend requests a blob but then creates a new Blob without a type, losing the
server’s MIME metadata.

backend/src/controllers/exportController.ts[24-36]
frontend/src/App.tsx[180-209]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
TXT export encodes bytes as UTF-8 but the response does not specify a charset, and the frontend discards the response MIME type when creating the download Blob.

### Issue Context
- Backend: `Buffer.from(text, 'utf-8')` is used for TXT, but `Content-Type` is set to `text/plain` without `charset=utf-8`.
- Frontend: axios uses `responseType: 'blob'`, but code constructs `new Blob([response.data])` without passing a `type`, which drops the server-provided content type.

### Fix Focus Areas
- backend/src/controllers/exportController.ts[24-36]
- frontend/src/App.tsx[191-209]

### Suggested changes
1. **Backend**: set `contentType = 'text/plain; charset=utf-8'` for TXT.
2. **Frontend**: avoid re-wrapping the Blob (use `URL.createObjectURL(response.data)`), or create the Blob with an explicit `type` from `response.headers['content-type']` (fallback to `text/plain; charset=utf-8`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export as .txt File 📄

1 participant