mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
Create a blocking call for jsonrpc
This commit is contained in:
@@ -1341,32 +1341,49 @@ impl CommandApi {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Starts to provide the backup for remote devices to retrieve.
|
||||
/// Offers a backup for remote devices to retrieve.
|
||||
///
|
||||
/// Can be cancelled by stopping the ongoing process. Success or failure can be tracked
|
||||
/// via the `ImexProgress` event which should either reach `1000` for success or `0` for
|
||||
/// failure.
|
||||
///
|
||||
/// This **stops IO**. After completion `start_io` must be called to restart IO.
|
||||
/// This **stops IO** while it is running.
|
||||
///
|
||||
/// Returns the QR code as a rendered SVG image.
|
||||
async fn provide_backup(&self, account_id: u32) -> Result<String> {
|
||||
/// Returns once a remote device has retrieved the backup.
|
||||
async fn provide_backup(&self, account_id: u32) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
ctx.stop_io().await;
|
||||
let provider = imex::BackupProvider::prepare(&ctx).await?;
|
||||
let qr = provider.qr();
|
||||
let svg = match generate_backup_qr(&ctx, &qr).await {
|
||||
Ok(svg) => svg,
|
||||
let provider = match imex::BackupProvider::prepare(&ctx).await {
|
||||
Ok(provider) => provider,
|
||||
Err(err) => {
|
||||
ctx.stop_ongoing().await;
|
||||
ctx.start_io().await;
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
Ok(svg)
|
||||
let res = provider.join().await;
|
||||
ctx.start_io().await;
|
||||
res
|
||||
}
|
||||
|
||||
/// Returns the QR code for the running [`CommandApi::provide_backup`].
|
||||
///
|
||||
/// This QR code can be used in [`CommandApi::get_backup`] on a second device to
|
||||
/// retrieve the backup and setup this second device.
|
||||
///
|
||||
/// Returns the QR code rendered as an SVG image.
|
||||
async fn get_backup_qr_svg(&self, account_id: u32) -> Result<String> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
let qr = ctx
|
||||
.backup_export_qr()
|
||||
.ok_or(anyhow!("no backup being exported"))?;
|
||||
generate_backup_qr(&ctx, &qr).await
|
||||
}
|
||||
|
||||
/// Gets a backup from a remote provider.
|
||||
///
|
||||
/// This retrieves the backup from a remote device over the network and imports it into
|
||||
/// the current device.
|
||||
///
|
||||
/// Can be cancelled by stopping the ongoing process.
|
||||
async fn get_backup(&self, account_id: u32, qr_text: String) -> Result<()> {
|
||||
let ctx = self.get_context(account_id).await?;
|
||||
|
||||
Reference in New Issue
Block a user