hailin
|
e16ec7930d
|
feat(knowledge): add file upload with text extraction for knowledge base
支持在管理后台知识库页面上传文件(PDF、Word、TXT、Markdown),
自动提取文本内容,管理员预览编辑后保存为知识库文章。
## 后端 (knowledge-service)
- 新增 TextExtractionService:文件文本提取服务
- PDF 提取:使用 pdf-parse v2 (PDFParse class API)
- Word (.docx) 提取:使用 mammoth.extractRawText()
- TXT/Markdown:直接 UTF-8 解码
- 支持中英文混合字数统计
- 文件大小限制 200MB,类型校验(MIME 白名单)
- 空文本 PDF(扫描件/图片)返回友好错误提示
- 新增上传接口:POST /knowledge/articles/upload
- 使用 NestJS FileInterceptor 处理 multipart/form-data
- 仅提取文本并返回,不直接创建文章(两步流程)
- 返回:extractedText, suggestedTitle, wordCount, pageCount
- 新增 ExtractedTextResponse DTO
- KnowledgeModule 注册 TextExtractionService
## 前端 (admin-client)
- knowledge.api.ts:新增 uploadFile() 方法(FormData + 120s 超时)
- useKnowledge.ts:新增 useUploadKnowledgeFile hook
- KnowledgePage.tsx:
- 新增 Segmented 切换器(手动输入 / 文件上传),仅新建时显示
- 文件上传模式显示 Upload.Dragger 拖拽上传区域
- 上传后自动提取文本,填入标题+内容字段
- 提取完成自动切回手动模式,管理员可预览编辑后保存
- 显示提取结果(字数、页数)
## 用户流程
新建文章 → 切换"文件上传" → 拖入/选择文件 → 系统提取文本
→ 自动填入标题+内容 → 管理员编辑确认 → 点击保存
## 依赖
- pdf-parse@^2.4.5(PDF 文本提取)
- mammoth@^1.8.0(Word 文档文本提取)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
2026-02-06 22:58:19 -08:00 |
hailin
|
9e1dca25f2
|
refactor(admin-client): implement 3-layer Clean Architecture for frontend
Refactored admin-client from 1.5-layer to 3-layer architecture using
Feature-Sliced Design pattern with Zustand + TanStack Query.
## Architecture Pattern
Each feature now follows 3-layer structure:
```
features/{feature}/
├── presentation/ # React UI components, pages
├── application/ # Zustand stores, TanStack Query hooks
└── infrastructure/ # API clients (axios calls)
```
## Changes by Feature
### Auth Feature
- infrastructure/auth.api.ts: Login, verify API calls
- application/useAuthStore.ts: Zustand store for auth state
- Updated LoginPage.tsx to use useAuthStore
- shared/hooks/useAuth.ts: Re-exports for backward compatibility
### Knowledge Feature
- infrastructure/knowledge.api.ts: Article CRUD APIs
- application/useKnowledge.ts: TanStack Query hooks
- useKnowledgeArticles, useCreateArticle, useUpdateArticle
- useDeleteArticle, usePublishArticle, useUnpublishArticle
- Updated KnowledgePage.tsx to use application hooks
### Experience Feature
- infrastructure/experience.api.ts: Experience management APIs
- application/useExperience.ts: TanStack Query hooks
- usePendingExperiences, useExperienceStatistics
- useApproveExperience, useRejectExperience, useRunEvolution
- Updated ExperiencePage.tsx to use application hooks
### Dashboard Feature
- infrastructure/dashboard.api.ts: Statistics APIs
- application/useDashboard.ts: TanStack Query hooks
- useEvolutionStatistics, useSystemHealth
- Updated DashboardPage.tsx to use application hooks
## Benefits
- Clear separation of concerns (UI / business logic / data access)
- Better testability (each layer can be tested independently)
- Reusable hooks across components
- Type-safe API interfaces
- Centralized API error handling
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
2026-01-24 22:17:48 -08:00 |