feat: improve JSONL support for content import#58
Conversation
|
@copilot 如果是 [{}] 这样的可以被解析的内容,就每一个 object 被 JSON.stringlify 之后作为一个内容 |
Co-authored-by: U8F69 <41963680+U8F69@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
此 PR 增强了内容导入时对 JSONL 的支持,新增对 JSON 数组格式的解析并保持向后兼容,同时更新了前端输入提示。
- 在
parseImportContent中新增对[...]JSON 数组格式的识别和解析 - 保留原有按行和逗号分隔的解析逻辑,智能回退无效 JSON 时使用旧逻辑
- 更新批量导入界面
Textarea的占位提示,列出支持的多种格式
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| frontend/components/common/project/constants.ts | 修改 parseImportContent 函数,支持 JSON 数组格式解析 |
| frontend/components/common/project/BulkImportSection.tsx | 更新导入文本框占位提示,列出三种批量导入格式 |
Comments suppressed due to low confidence (1)
frontend/components/common/project/constants.ts:72
- parseImportContent 函数新增了对 JSON 数组格式的解析逻辑,但缺少对应的单元测试用例。建议补充测试以覆盖有效和无效 JSON 数组的解析场景,确保功能稳定。
if (trimmedContent.startsWith('[') && trimmedContent.endsWith(']')) {
|
@copilot 修改下 PR 的描述内容,需要遵循 PR 模板 |
已按照 PR 模板重新格式化描述内容,包含例行检查、关联信息、变更内容和变更原因四个标准部分。 |
|
@copilot |
Co-authored-by: U8F69 <41963680+U8F69@users.noreply.github.com>
已完成 JSONL 文件支持功能: ✅ 文件导入现在支持 .txt 和 .jsonl 格式 JSONL 文件支持两种格式:
所有修改保持向后兼容,现有的 TXT 文件导入功能不受影响。 Commit: c78cce6 Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot fix eslint warning |
Co-authored-by: U8F69 <41963680+U8F69@users.noreply.github.com>
问题描述
当前系统在导入 JSONL 格式内容时,会错误地将 JSON 对象内部的逗号当作分隔符,导致完整的 JSON 对象被分割成多个部分。
如下图所示,原本应该是一个完整的 JSON 对象
{"email": "neo@harvard.edu", "password": "P%IF3nSI4mIK"}被错误地分成了两行:{"email": "neo@harvard.edu""password": "P%IF3nSI4mIK"}解决方案
根据 @U8F69 的建议,实现了多种识别模式:
核心功能改进
JSON 数组格式支持 -
[{}, {}, {}][开始且以]结束的内容智能回退机制
完全向后兼容
代码变更
修改
parseImportContent函数(frontend/components/common/project/constants.ts):更新用户界面提示(
frontend/components/common/project/BulkImportSection.tsx):测试验证
✅ 原问题场景:JSON 数组
[{"email": "neo@harvard.edu", "password": "P%IF3nSI4mIK"}, {...}]正确解析为 2 个独立项目✅ 复杂 JSON:包含嵌套数组和多个逗号的情况正确处理
✅ 向后兼容:传统的逗号分隔和每行一个内容格式仍然正常工作
✅ 错误处理:无效 JSON 智能回退到传统解析逻辑
功能特点
Fixes #54.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/usr/local/bin/node /home/REDACTED/work/cdk/cdk/frontend/node_modules/next/dist/compiled/jest-worker/processChild.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.