Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export sync config #4902

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

bygsn
Copy link

@bygsn bygsn commented Jun 30, 2024

Export and Import Sync Configuration as Compressed String

Overview

This PR introduces a feature to export sync configurations as compressed strings, automatically copy them to the clipboard, and provide an import function to apply these configurations. This enhancement facilitates easy cross-platform synchronization of cloud data settings.

Implementation Details

  • Added export and import buttons in the cloud data section of the settings interface
  • Implemented compression of current sync configurations into string format
  • Integrated clipboard functionality for automatic copying of exported strings
  • Added import functionality to parse compressed strings and update sync configurations
  • Implemented pop-up notifications for export, copy, and import operation statuses

Motivation

This feature improves user experience by simplifying configuration transfer between devices or platforms, allowing users to easily share or backup settings without manual copying and eliminating transcription error risks.

Usage and Screenshots

Exporting Configuration

export
Figure 1: Export Sync Configuration Process

  1. Navigate to the Cloud Data section
  2. Click the "Configure" button
  3. Enter sync configuration and confirm
  4. Click the "Export" button that appears
  5. Configuration is automatically copied to clipboard
  6. Success message: "Sync configuration copied to clipboard"
    (Failure message: "Sync configuration export failed. Please try again")

Importing Configuration

import
Figure 2: Import Sync Configuration Process

  1. Navigate to the Cloud Data section on target device/platform
  2. Click the "Import" button
  3. Paste the copied string into the "Import Sync Configuration" window
  4. Click "Confirm" to import
  5. Success message: "Sync configuration imported successfully"
    (Failure message: "Sync configuration import failed. Please check the configuration string")
  6. Click sync button to complete data synchronization

Testing

  1. Export Configuration:

    • Follow export steps and verify success message
    • Confirm compressed string in a text editor
  2. Import Configuration:

    • Follow import steps on another device/browser
    • Verify correct application of imported settings
    • Confirm sync settings update as expected

Related Issues

Additional Notes

  • Compressed string ensures compactness and excludes sensitive data
  • Error handling implemented for invalid import strings

This PR targets the main branch. Please advise if it should be directed elsewhere.

Feedback and improvement suggestions are welcome. Thank you for your review!

Summary by CodeRabbit

  • New Features

    • Added the ability to import and export synchronization configurations via a new modal in the settings.
  • Localization

    • Added Chinese and English translations for import/export sync configurations, including success and failure messages.
  • UI Enhancements

    • Introduced new icons and style adjustments for the import/export feature.
  • Dependencies

    • Updated dependencies to include the pako library for handling data compression.

Copy link

vercel bot commented Jun 30, 2024

Someone is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jun 30, 2024

Walkthrough

These changes introduce a new feature for exporting and importing synchronization configurations in the application. A modal interface was added for importing configurations, along with relevant state management and icons in the settings component. New localized strings were added to support these functionalities in multiple languages. The backend logic in the sync store was enhanced to handle exporting and importing configurations, leveraging the pako library for data compression.

Changes

File(s) Summary
app/components/settings.module.scss Added styles for .import-config-modal and nested .import-config-content.
app/components/settings.tsx Added UI imports, icon imports, ImportConfigModal component, state and logic for import modal, and buttons for data import/export.
app/locales/cn.ts, app/locales/en.ts Added new localization strings for import/export functionalities and their respective messages.
app/store/sync.ts Added pako import. Implemented exportSyncConfig and importSyncConfig functions for handling synchronization configurations. Updated cloudSync with revised error handling.
package.json Added pako to dependencies and @types/pako to devDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as UI Components
    participant Settings as Settings Component
    participant Store as Sync Store

    User->>UI: Click on Import Button
    UI->>Settings: Show Import Modal
    Settings->>Settings: User Enters Config Data
    Settings->>Store: Call importSyncConfig(data)
    Store->>Settings: Return Success/Failure
    Settings->>UI: Display Result Message
Loading

Assessment against linked issues

Objective Addressed Explanation
Add cloud sync parameters to environment variables (#4892) This change does not address environment variables.
Provide fixed sync settings across devices without re-setup (#3760)

Poem

Amidst the code, a rabbit toils,
To sync the clouds and ease the spoils.
With icons bright and buttons neat,
Configs now smoothly import and export fleet.
Rejoice, dear coders, in this feat!


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are always opted into early access features.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Your build has completed!

Preview deployment

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Outside diff range and nitpick comments (19)
app/components/settings.tsx (19)

Line range hint 105-105: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onInput={(e) => promptStore.updatePrompt(props.id, (prompt) => (prompt.title = e.currentTarget.value))}
+ onInput={(e) => {
+   const newTitle = e.currentTarget.value;
+   promptStore.updatePrompt(props.id, (prompt) => {
+     prompt.title = newTitle;
+   });
+ }}

Line range hint 117-117: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onInput={(e) => promptStore.updatePrompt(props.id, (prompt) => (prompt.content = e.currentTarget.value))}
+ onInput={(e) => {
+   const newContent = e.currentTarget.value;
+   promptStore.updatePrompt(props.id, (prompt) => {
+     prompt.content = newContent;
+   });
+ }}

Line range hint 340-340: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.provider = e.target.value as ProviderType))}
+ onChange={(e) => {
+   const newProvider = e.target.value as ProviderType;
+   syncStore.update((config) => {
+     config.provider = newProvider;
+   });
+ }}

Line range hint 361-361: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.useProxy = e.currentTarget.checked))}
+ onChange={(e) => {
+   const useProxy = e.currentTarget.checked;
+   syncStore.update((config) => {
+     config.useProxy = useProxy;
+   });
+ }}

Line range hint 376-376: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.proxyUrl = e.currentTarget.value))}
+ onChange={(e) => {
+   const proxyUrl = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.proxyUrl = proxyUrl;
+   });
+ }}

Line range hint 394-394: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.webdav.endpoint = e.currentTarget.value))}
+ onChange={(e) => {
+   const endpoint = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.webdav.endpoint = endpoint;
+   });
+ }}

Line range hint 407-407: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.webdav.username = e.currentTarget.value))}
+ onChange={(e) => {
+   const username = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.webdav.username = username;
+   });
+ }}

Line range hint 418-418: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.webdav.password = e.currentTarget.value))}
+ onChange={(e) => {
+   const password = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.webdav.password = password;
+   });
+ }}

Line range hint 436-436: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.upstash.endpoint = e.currentTarget.value))}
+ onChange={(e) => {
+   const endpoint = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.upstash.endpoint = endpoint;
+   });
+ }}

Line range hint 450-450: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.upstash.username = e.currentTarget.value))}
+ onChange={(e) => {
+   const username = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.upstash.username = username;
+   });
+ }}

Line range hint 460-460: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => syncStore.update((config) => (config.upstash.apiKey = e.currentTarget.value))}
+ onChange={(e) => {
+   const apiKey = e.currentTarget.value;
+   syncStore.update((config) => {
+     config.upstash.apiKey = apiKey;
+   });
+ }}

Line range hint 766-766: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((state) => (state.useCustomConfig = e.currentTarget.checked))}
+ onChange={(e) => {
+   const useCustomConfig = e.currentTarget.checked;
+   accessStore.update((state) => {
+     state.useCustomConfig = useCustomConfig;
+   });
+ }}

Line range hint 773-778: Ensure keyboard accessibility for click events.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

- onClick={() => setShowEmojiPicker(!showEmojiPicker)}
+ onClick={() => setShowEmojiPicker(!showEmojiPicker)}
+ onKeyDown={(e) => {
+   if (e.key === "Enter" || e.key === " ") {
+     setShowEmojiPicker(!showEmojiPicker);
+   }
+ }}
+ tabIndex={0}
+ role="button"

Line range hint 815-815: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.useCustomConfig = e.currentTarget.checked))}
+ onChange={(e) => {
+   const useCustomConfig = e.currentTarget.checked;
+   accessStore.update((access) => {
+     access.useCustomConfig = useCustomConfig;
+   });
+ }}

Line range hint 832-832: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.provider = e.target.value as ServiceProvider))}
+ onChange={(e) => {
+   const provider = e.target.value as ServiceProvider;
+   accessStore.update((access) => {
+     access.provider = provider;
+   });
+ }}

Line range hint 872-872: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.openaiUrl = e.currentTarget.value))}
+ onChange={(e) => {
+   const openaiUrl = e.currentTarget.value;
+   accessStore.update((access) => {
+     access.openaiUrl = openaiUrl;
+   });
+ }}

Line range hint 888-888: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.openaiApiKey = e.currentTarget.value))}
+ onChange={(e) => {
+   const openaiApiKey = e.currentTarget.value;
+   accessStore.update((access) => {
+     access.openaiApiKey = openaiApiKey;
+   });
+ }}

Line range hint 904-904: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.azureUrl = e.currentTarget.value))}
+ onChange={(e) => {
+   const azureUrl = e.currentTarget.value;
+   accessStore.update((access) => {
+     access.azureUrl = azureUrl;
+   });
+ }}

Line range hint 924-925: Refactor assignment within JSX expression.

The assignment within the JSX expression can be confusing. Refactor it to improve readability.

- onChange={(e) => accessStore.update((access) => (access.azureApiVersion = e.currentTarget.value))}
+ onChange={(e) => {
+   const azureApiVersion = e.currentTarget.value;
+   accessStore.update((access) => {
+     access.azureApiVersion = azureApiVersion;
+   });
+ }}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c359b30 and c234160.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (6)
  • app/components/settings.module.scss (1 hunks)
  • app/components/settings.tsx (6 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/en.ts (1 hunks)
  • app/store/sync.ts (3 hunks)
  • package.json (2 hunks)
Files skipped from review due to trivial changes (1)
  • app/components/settings.module.scss
Additional context used
Biome
app/store/sync.ts

[error] 150-156: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

app/components/settings.tsx

[error] 105-105: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 117-117: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 340-340: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 361-361: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 376-376: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 394-394: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 407-407: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 418-418: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 436-436: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 450-450: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 460-460: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 513-513: Avoid the autoFocus attribute.

Unsafe fix: Remove the autoFocus attribute.

(lint/a11y/noAutofocus)


[error] 766-766: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 773-778: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


[error] 815-815: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 832-832: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 872-872: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 888-888: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 904-904: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 924-925: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

Additional comments not posted (4)
package.json (1)

33-33: LGTM!

The additions of pako and @types/pako are appropriate for the new import/export functionality.

Also applies to: 51-51

app/store/sync.ts (1)

73-92: LGTM!

The importSyncConfig function is well-implemented and includes proper error handling.

app/locales/cn.ts (1)

188-200: LGTM!

The new localization keys for the import/export functionality are correctly added.

app/locales/en.ts (1)

190-202: LGTM!

The new localization keys for the import/export functionality are correctly added.

app/store/sync.ts Show resolved Hide resolved
app/store/sync.ts Show resolved Hide resolved
app/components/settings.tsx Show resolved Hide resolved
app/components/settings.tsx Show resolved Hide resolved
app/components/settings.tsx Show resolved Hide resolved
bygsn referenced this pull request Jul 2, 2024
bygsn referenced this pull request Jul 2, 2024
fix: make env PROXY_URL avaliable in Docker container.
bygsn referenced this pull request Jul 2, 2024
- Added 'bora.teracloud.jp' to the list of supported domains.
bygsn referenced this pull request Jul 2, 2024
@ImBIOS
Copy link
Contributor

ImBIOS commented Jul 3, 2024

@KILL4M let me answer you question in my comit here:

Answer

  1. You're good. For outsider, it's normal. Because Vercel deployment requires some level of internal team access.
  2. I've done review on this PR. To make it simple, what @coderabbitai does is already great:
  3. 2 options:
    a. simple: just report issue, engage in discussion, report security vuln, or made a PR and let the maintianer or reviewer decide wether it's helpful or not.
    b. takes time: before engage in any open source activity, always read the contributing guideline, security document, license, code of conduct and any rules that have been set by the internal team of that open source project and you'll get anythin you need in those documents.

Welcome to open source, I recommend to active engaging in open source activity after your main job is done perfectly. Don't make this a main job, no one paying you for living... except donation.

I recommend you to not opening a discussion in some of the merged commit like this. There's better option like discussions tab, or inside the PR or issue you're active on. My first thought when my commit got commented is, "what's wrong with my merged single line commit? I need to rush to my desktop ASAP and fix it", thanks God it's just some questions not some disastrous thingy.

@ImBIOS
Copy link
Contributor

ImBIOS commented Jul 3, 2024

@KILL4M I found out you're spamming some merged commit just to ask questions, email is better way to spam people tho (cause there's filtering function there 😅), please don't do that.

This https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web project is an open source non profit project. I even not expecting them to care about this project much, because they should care more about their food on the table. Which tech industry currently in trouble especially in Mainland China which the most of the maintainer team geographically located. Please have patience or just work on your fork, like everyone in open source community does. Or you can financially support the maintainer if you think this is important and urgent matter so they can have time to focus on your problem while their bills paid.

If it's in my open source project, I might temporarily ban you for the spam. That's how bad it is spamming in another people's merged commit.

Copy link

coderabbitai bot commented Jul 3, 2024

@ImBIOS: Thank you for providing detailed feedback and guidance. It's crucial for contributors to understand the appropriate ways to engage in open-source projects and follow the guidelines set by the maintainers. If there are any further questions or issues, feel free to reach out, and I'll be happy to assist.

Actions performed

Comments resolved.

Copy link
Contributor

@ImBIOS ImBIOS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix all the @coderabbitai request first.

@ChatGPTNextWeb ChatGPTNextWeb locked as spam and limited conversation to collaborators Jul 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: 云端同步 [help]云同步和自定义接口有办法写在docker配置里么?
3 participants