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

[Cloud Sync] #2854

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

[Cloud Sync] #2854

wants to merge 16 commits into from

Conversation

H0llyW00dzZ
Copy link
Contributor

[+] Add support for GithubGist synchronization in useSyncStore

  • Updated the WebDavConfig interface to include the filename property.
  • Added the GistConfig interface to define the filename, gistId, and token for GitHub Gist synchronization.
  • Modified the createPersistStore function in the useSyncStore module to include the githubGist and upstash properties in the initial state, with empty values for their respective properties.
  • Added the lastUpdateTime and syncing properties to the initial state to track the last update time and synchronization status.
  • Updated the sync method to handle the synchronization logic for WebDAV, including merging the remote state, updating the local state, and overwriting access control settings if specified.
  • Implemented the markUpdateTime method to update the last update time when performing synchronization.
  • Added the countSync method to check if all required configuration values for the selected provider are filled.
  • Modified the export method to generate a backup file name based on the current date and time.
  • Updated the import method to handle importing JSON files split into multiple chunks.
  • Updated the sync method to handle merging filtered topics and updating masks.
  • Added the necessary dependencies and ensured that the createSyncClient function in the cloud module accepts the required arguments for setting up the data.

These changes extend the useSyncStore module to support synchronization with WebDAV in addition to GitHub Gist and Upstash. The module now provides methods to sync, export, import, and check synchronization state with the selected provider. The code also includes improvements for handling synchronization and merging state, as well as managing access control settings.

[+] Fix locale language inconsistencies in useSyncStore

  • Updated the text strings in the useSyncStore module to ensure consistent and accurate locale language usage throughout the codebase.

[+] Add support for GithubGist synchronization in useSyncStore

- Updated the `WebDavConfig` interface to include the `filename` property.
- Added the `GistConfig` interface to define the filename, gistId, and token for GitHub Gist synchronization.
- Modified the `createPersistStore` function in the `useSyncStore` module to include the `githubGist` and `upstash` properties in the initial state, with empty values for their respective properties.
- Added the `lastUpdateTime` and `syncing` properties to the initial state to track the last update time and synchronization status.
- Updated the `sync` method to handle the synchronization logic for WebDAV, including merging the remote state, updating the local state, and overwriting access control settings if specified.
- Implemented the `markUpdateTime` method to update the last update time when performing synchronization.
- Added the `countSync` method to check if all required configuration values for the selected provider are filled.
- Modified the `export` method to generate a backup file name based on the current date and time.
- Updated the `import` method to handle importing JSON files split into multiple chunks.
- Updated the `sync` method to handle merging filtered topics and updating masks.
- Added the necessary dependencies and ensured that the `createSyncClient` function in the `cloud` module accepts the required arguments for setting up the data.

These changes extend the `useSyncStore` module to support synchronization with WebDAV in addition to GitHub Gist and Upstash. The module now provides methods to sync, export, import, and check synchronization state with the selected provider. The code also includes improvements for handling synchronization and merging state, as well as managing access control settings.

[+] Fix locale language inconsistencies in `useSyncStore`

- Updated the text strings in the `useSyncStore` module to ensure consistent and accurate locale language usage throughout the codebase.
@H0llyW00dzZ
Copy link
Contributor Author

Note

Details for GithubGist

GitHub Gist supports multiple files
Estimating Lines in 100MB

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Note

Details for GithubGist

GitHub Gist supports multiple files
Estimating Lines in 100MB

@H0llyW00dzZ
Copy link
Contributor Author

Preview Github Gist Sync :
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Preview Github Gist Sync :
image

- Fix 'client.set is not a function' error and update 'set' method to handle different value types
- Introduce separate synchronization methods for WebDAV and GitHub Gist providers
- Implement provider-specific synchronization logic in the 'sync' method
- Update 'syncWebDAV' to correctly set data using 'client.set' with 'filename' and 'JSON.stringify(localState)'
- Update 'syncGitHubGist' to properly set data using 'client.set' with 'localState' and 'value
- Enhance 'set' method in 'SyncClient' to accept both 'Object' and 'string' as 'value' parameters
- Ensure correct passing of 'localState' and 'value' in 'syncGitHubGist' method for GitHub Gist synchronization
Copy link
Contributor Author

@H0llyW00dzZ H0llyW00dzZ left a comment

Choose a reason for hiding this comment

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

Github Gist ✅

  • Enhance 'set' method in 'SyncClient' to accept both 'Object' and 'string' as 'value' parameters

app/utils/cloud/index.ts Show resolved Hide resolved
@H0llyW00dzZ
Copy link
Contributor Author

H0llyW00dzZ commented Sep 18, 2023

additional note for an improvement webdav in this PR already added

image

after attempt fix by automated

image

H0llyW00dzZ and others added 6 commits September 18, 2023 19:48
[+] Update `check` method to use `PROPFIND` instead of `MKCOL`

In the `webdav.ts` module, updated the `check` method to use the `PROPFIND` method instead of `MKCOL` to check if the file exists. This change was made to handle cases where the server does not allow the `MKCOL` method. The `PROPFIND` method is used to retrieve the properties of the file, and if the response status is either 200 (OK), 207 (Multi-Status), or 404 (Not Found), it considers the file to exist.
- fix(settings): remove unnecessary code for syncing with GitHub Gist provider
- fix(sync): change console.error to console.log for failed remote state retrieval from file
- fix(gist): simplify logic for checking if Gist exists or not
[+] feat(gist.ts): implement content chunking for gist creation
[+] fix(sync.ts): swap merge order in mergeWithUpdate function
[+] feat(route.ts): change runtime from nodejs to edge
[+] refactor(sync.ts): extract default sync state to a constant
[+] fix(sync.ts): correct accessControl properties assignment
[+] feat(sync.ts): add migration function for version 1.1 to update upstash username
@H0llyW00dzZ H0llyW00dzZ changed the title SyncService [Cloud Sync] Sep 20, 2023
[+] fix(route.ts): set CORS headers for preflight requests in handle function
[+] feat(route.ts): add support for Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, and Access-Control-Max-Age headers in preflight requests
[+] feat(format.ts): add function to split a string into chunks based on byte size
[+] fix(gist.ts): fix indentation and remove unnecessary comments
[+] chore(gist.ts): update console.log messages for better readability
[+] fix(webdav.ts): update console.log messages for better readability
[+] refactor(settings.tsx): remove unnecessary code and reorganize CheckButton component logic
Copy link

@kkocdko kkocdko left a comment

Choose a reason for hiding this comment

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

Look great to me.

@@ -150,7 +150,7 @@ export function mergeWithUpdate<T extends { lastUpdateTime?: number }>(
remoteState: T,
) {
const localUpdateTime = localState.lastUpdateTime ?? 0;
const remoteUpdateTime = localState.lastUpdateTime ?? 1;
const remoteUpdateTime = remoteState.lastUpdateTime ?? 1;
Copy link

@kkocdko kkocdko Dec 31, 2023

Choose a reason for hiding this comment

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

Hope this fix can be merged soon. Maybe a separate PR?

Related to #3578 and #3001

},

export() {
const state = getLocalAppState();
const fileName = `Backup-${new Date().toLocaleString()}.json`;
downloadAs(JSON.stringify(state), fileName);
const fileName = `Backup-${new Date().toLocaleString()}`;
Copy link

Choose a reason for hiding this comment

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

Is this change necessary? Can we just keep downloadAs receive string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this change necessary? Can we just keep downloadAs receive string?

that branch are outdated
a better one already implemented here:

    export() {
      const state = getLocalAppState();
      const datePart = isApp
        ? `${new Date().toLocaleDateString().replace(/\//g, '_')} ${new Date().toLocaleTimeString().replace(/:/g, '_')}`
        : new Date().toLocaleString();

      const fileName = `Backup-${datePart}.json`;
      downloadAs((state), fileName);
    },

@daiaji
Copy link

daiaji commented Mar 9, 2024

Is this PR outdated? Is there a new PR to fix the current cloud sync behavior? To be honest, the current cloud sync is quite poor.

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.

4 participants