feat: export and import data#101
Conversation
Co-authored-by: self <self@lemonneko.moe>
|
Cursor Agent can help with this pull request. Just |
✅ Deploy Preview for flow-chat ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Summary of ChangesHello @LemonNekoGH, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new feature that enables users to export all their application data, such as chat rooms, messages, and templates, into a downloadable JSON file. This provides users with greater control over their data, allowing for backups or migration, while intentionally excluding sensitive embedding models. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a data export feature, allowing users to download their application data as a JSON file. The core logic is well-encapsulated within a new useExportModel composable. The settings page is updated with a new button to trigger this export, including a loading state. My review focuses on improving code consistency, ensuring data integrity in the exported file's name, and adding crucial error handling to enhance the user experience.
| const [templates, rooms, messages, memories, toolCalls] = await Promise.all([ | ||
| db.select().from(schema.templates), | ||
| db.select().from(schema.rooms), | ||
| db.select({ | ||
| id: schema.messages.id, | ||
| content: schema.messages.content, | ||
| model: schema.messages.model, | ||
| provider: schema.messages.provider, | ||
| role: schema.messages.role, | ||
| room_id: schema.messages.room_id, | ||
| parent_id: schema.messages.parent_id, | ||
| summary: schema.messages.summary, | ||
| show_summary: schema.messages.show_summary, | ||
| memory: schema.messages.memory, | ||
| created_at: schema.messages.created_at, | ||
| updated_at: schema.messages.updated_at, | ||
| // embedding is excluded from export | ||
| }).from(schema.messages), | ||
| db.select().from(schema.memories), | ||
| db.select().from(schema.tool_calls), | ||
| ]) | ||
|
|
||
| return { | ||
| version: '1.0.0', | ||
| exportedAt: new Date().toISOString(), | ||
| templates, | ||
| rooms, | ||
| messages, | ||
| memories, | ||
| tool_calls: toolCalls, | ||
| } |
There was a problem hiding this comment.
For consistency with other destructured variables and property names, it's better to name the variable tool_calls instead of toolCalls. This allows you to use the shorthand property syntax in the return object, making the code slightly cleaner and more consistent.
const [templates, rooms, messages, memories, tool_calls] = await Promise.all([
db.select().from(schema.templates),
db.select().from(schema.rooms),
db.select({
id: schema.messages.id,
content: schema.messages.content,
model: schema.messages.model,
provider: schema.messages.provider,
role: schema.messages.role,
room_id: schema.messages.room_id,
parent_id: schema.messages.parent_id,
summary: schema.messages.summary,
show_summary: schema.messages.show_summary,
memory: schema.messages.memory,
created_at: schema.messages.created_at,
updated_at: schema.messages.updated_at,
// embedding is excluded from export
}).from(schema.messages),
db.select().from(schema.memories),
db.select().from(schema.tool_calls),
])
return {
version: '1.0.0',
exportedAt: new Date().toISOString(),
templates,
rooms,
messages,
memories,
tool_calls,
}|
|
||
| const link = document.createElement('a') | ||
| link.href = url | ||
| link.download = `flow-chat-export-${new Date().toISOString().slice(0, 10)}.json` |
There was a problem hiding this comment.
The date for the filename is generated here using new Date(), while the exportedAt field in the JSON data is generated earlier in exportAllData. If the export process happens to cross midnight, the date in the filename could be different from the date in exportedAt. To ensure consistency, you should use the exportedAt value from the data object for the filename.
| link.download = `flow-chat-export-${new Date().toISOString().slice(0, 10)}.json` | |
| link.download = `flow-chat-export-${data.exportedAt.slice(0, 10)}.json` |
| async function exportAllData() { | ||
| isExporting.value = true | ||
| try { | ||
| await exportModel.exportAndDownload() | ||
| } | ||
| finally { | ||
| isExporting.value = false | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation will correctly reset the isExporting state if an error occurs, but it won't inform the user that the export failed. It's good practice to add a catch block to handle potential errors from the export process, log them, and provide feedback to the user (e.g., via an alert or a toast notification).
async function exportAllData() {
isExporting.value = true
try {
await exportModel.exportAndDownload()
}
catch (error) {
console.error('Failed to export data:', error)
// Consider using a toast notification for a better user experience
alert('Failed to export data. Please check the console for more details.')
}
finally {
isExporting.value = false
}
}
Co-authored-by: self <self@lemonneko.moe>
This commit introduces the ability to import data from JSON files and database dumps. It includes new functions in the export model for handling these imports, updates the settings page to provide UI elements for triggering imports, and modifies the database store to manage pending imports and load data from dumps. Co-authored-by: self <self@lemonneko.moe>
The database dump import functionality has been removed as it was complex and not widely used. Co-authored-by: self <self@lemonneko.moe>
Co-authored-by: self <self@lemonneko.moe>
Co-authored-by: self <self@lemonneko.moe>
Implement a data export feature to allow users to download all application data, excluding embedding models.