mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 11:43:57 +08:00
feat(pi): add native catalog and gateway data plane
This commit is contained in:
@@ -107,18 +107,44 @@ pub async fn s3_sync_upload(state: State<'_, AppState>) -> Result<Value, String>
|
||||
#[tauri::command]
|
||||
pub async fn s3_sync_download(state: State<'_, AppState>) -> Result<Value, String> {
|
||||
let db = state.db.clone();
|
||||
let db_for_sync = db.clone();
|
||||
let app_state = state.inner().clone();
|
||||
let mut settings = require_enabled_s3_settings()?;
|
||||
let _auto_sync_suppression = crate::services::s3_auto_sync::AutoSyncSuppressionGuard::new();
|
||||
|
||||
let pi_guard = app_state
|
||||
.proxy_service
|
||||
.lock_switch_for_app(crate::app_config::AppType::Pi.as_str())
|
||||
.await;
|
||||
app_state
|
||||
.proxy_service
|
||||
.prepare_pi_portable_import_under_lock(&pi_guard)
|
||||
.await
|
||||
.map_err(|error| format!("S3 下载前恢复 Pi 直连投影失败: {error}"))?;
|
||||
let sync_result = run_with_s3_lock(s3_sync_service::download(&db, &mut settings)).await;
|
||||
let mut result = map_sync_result(sync_result, |error| {
|
||||
persist_sync_error(&mut settings, error, "manual")
|
||||
})?;
|
||||
let mut result = match sync_result {
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
persist_sync_error(&mut settings, &error, "manual");
|
||||
let recovery = app_state
|
||||
.proxy_service
|
||||
.recover_pi_after_aborted_portable_import_under_lock(&pi_guard)
|
||||
.await;
|
||||
return Err(match recovery {
|
||||
Ok(()) => error.to_string(),
|
||||
Err(recovery) => {
|
||||
format!(
|
||||
"{error}; Pi gateway recovery after aborted S3 download failed: {recovery}"
|
||||
)
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
drop(pi_guard);
|
||||
|
||||
// Post-download sync is best-effort: snapshot restore has already succeeded.
|
||||
let sync_state = app_state.clone();
|
||||
let warning = post_sync_warning_from_result(
|
||||
tauri::async_runtime::spawn_blocking(move || run_post_import_sync(db_for_sync))
|
||||
tauri::async_runtime::spawn_blocking(move || run_post_import_sync(&sync_state))
|
||||
.await
|
||||
.map_err(|e| e.to_string()),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user