feat(sync): add GitHub and Gitee snippet providers
This commit is contained in:
1 parent
e429c8945b
commit
9e2960881b
15 files changed
+1220
-109
No files matched your search
@@ -1,12 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use dbx_core::cloud_sync::{
|
||||
apply_sync_snapshot, build_sync_snapshot_with_saved_secrets, forget_webdav_password,
|
||||
forget_webdav_sync_secrets_passphrase as core_forget_webdav_sync_secrets_passphrase, resolve_webdav_password,
|
||||
resolve_webdav_sync_secrets_passphrase, save_webdav_password,
|
||||
save_webdav_sync_secrets_preference as core_save_webdav_sync_secrets_preference, webdav_saved_password_status,
|
||||
webdav_sync_secrets_status as core_webdav_sync_secrets_status, ApplySnapshotOptions, ApplySnapshotSummary,
|
||||
WebDavClient, WebDavConfig, WebDavPasswordStatus, WebDavSyncSecretsStatus, WebDavSyncSummary,
|
||||
apply_sync_snapshot, build_sync_snapshot_with_saved_secrets, forget_snippet_token, forget_webdav_password,
|
||||
forget_webdav_sync_secrets_passphrase as core_forget_webdav_sync_secrets_passphrase, resolve_snippet_token,
|
||||
resolve_webdav_password, resolve_webdav_sync_secrets_passphrase, save_snippet_token, save_webdav_password,
|
||||
save_webdav_sync_secrets_preference as core_save_webdav_sync_secrets_preference, snippet_saved_token_status,
|
||||
webdav_saved_password_status, webdav_sync_secrets_status as core_webdav_sync_secrets_status, ApplySnapshotOptions,
|
||||
ApplySnapshotSummary, SnippetSyncClient, SnippetSyncConfig, SnippetSyncSummary, SnippetTokenStatus, WebDavClient,
|
||||
WebDavConfig, WebDavPasswordStatus, WebDavSyncSecretsStatus, WebDavSyncSummary,
|
||||
};
|
||||
use dbx_core::storage::DesktopSettings;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -23,6 +24,15 @@ pub struct WebDavDownloadResult {
|
||||
pub apply_summary: ApplySnapshotSummary,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SnippetDownloadResult {
|
||||
pub summary: SnippetSyncSummary,
|
||||
pub editor_settings: Option<serde_json::Value>,
|
||||
pub desktop_settings: DesktopSettings,
|
||||
pub apply_summary: ApplySnapshotSummary,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn webdav_sync_test(state: State<'_, Arc<AppState>>, mut config: WebDavConfig) -> Result<(), String> {
|
||||
resolve_webdav_password(&state.storage, &mut config).await?;
|
||||
@@ -115,3 +125,80 @@ pub async fn webdav_sync_download(
|
||||
apply_summary,
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn snippet_sync_test(state: State<'_, Arc<AppState>>, mut config: SnippetSyncConfig) -> Result<(), String> {
|
||||
resolve_snippet_token(&state.storage, &mut config).await?;
|
||||
SnippetSyncClient::new(config).test().await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn snippet_token_status(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
config: SnippetSyncConfig,
|
||||
) -> Result<SnippetTokenStatus, String> {
|
||||
snippet_saved_token_status(&state.storage, &config).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn save_snippet_saved_token(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
config: SnippetSyncConfig,
|
||||
token: String,
|
||||
) -> Result<(), String> {
|
||||
save_snippet_token(&state.storage, &config, &token).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn forget_snippet_saved_token(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
config: SnippetSyncConfig,
|
||||
) -> Result<(), String> {
|
||||
forget_snippet_token(&state.storage, &config).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn snippet_sync_upload(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
mut config: SnippetSyncConfig,
|
||||
editor_settings: Option<serde_json::Value>,
|
||||
secrets_passphrase: Option<String>,
|
||||
) -> Result<SnippetSyncSummary, String> {
|
||||
resolve_snippet_token(&state.storage, &mut config).await?;
|
||||
let snapshot = build_sync_snapshot_with_saved_secrets(
|
||||
&state.storage,
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
editor_settings,
|
||||
secrets_passphrase.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
SnippetSyncClient::new(config).put_snapshot(&snapshot).await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn snippet_sync_download(
|
||||
state: State<'_, Arc<AppState>>,
|
||||
mut config: SnippetSyncConfig,
|
||||
secrets_passphrase: Option<String>,
|
||||
) -> Result<SnippetDownloadResult, String> {
|
||||
resolve_snippet_token(&state.storage, &mut config).await?;
|
||||
let (snapshot, summary) = SnippetSyncClient::new(config).get_snapshot().await?;
|
||||
let explicit_passphrase = secrets_passphrase.as_deref().map(str::trim).filter(|value| !value.is_empty());
|
||||
let saved_passphrase = if explicit_passphrase.is_some() {
|
||||
None
|
||||
} else {
|
||||
resolve_webdav_sync_secrets_passphrase(&state.storage).await?
|
||||
};
|
||||
let apply_summary = apply_sync_snapshot(
|
||||
&state.storage,
|
||||
&snapshot,
|
||||
ApplySnapshotOptions { secrets_passphrase: explicit_passphrase.or(saved_passphrase.as_deref()) },
|
||||
)
|
||||
.await?;
|
||||
Ok(SnippetDownloadResult {
|
||||
summary,
|
||||
editor_settings: snapshot.editor_settings,
|
||||
desktop_settings: snapshot.desktop_settings,
|
||||
apply_summary,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user