Broadcast db changes
This commit is contained in:
parent
63a4948b87
commit
ed54a2391b
5 changed files with 24 additions and 5 deletions
|
|
@ -143,5 +143,10 @@ async fn internal_create_document(
|
||||||
.context("Failed to commit successful transaction")
|
.context("Failed to commit successful transaction")
|
||||||
.map_err(server_error)?;
|
.map_err(server_error)?;
|
||||||
|
|
||||||
|
state
|
||||||
|
.broadcasts
|
||||||
|
.send(vault_id, new_version.clone().into())
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Json(new_version.into()))
|
Ok(Json(new_version.into()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,5 +72,10 @@ pub async fn delete_document(
|
||||||
.context("Failed to commit successful transaction")
|
.context("Failed to commit successful transaction")
|
||||||
.map_err(server_error)?;
|
.map_err(server_error)?;
|
||||||
|
|
||||||
|
state
|
||||||
|
.broadcasts
|
||||||
|
.send(vault_id, new_version.clone().into())
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Json(new_version.into()))
|
Ok(Json(new_version.into()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use axum_typed_multipart::TryFromMultipart;
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{self, Deserialize};
|
use serde::{self, Deserialize};
|
||||||
|
|
||||||
use crate::database::models::{DocumentId, VaultUpdateId};
|
use crate::app_state::database::models::{DocumentId, VaultUpdateId};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, JsonSchema)]
|
#[derive(Debug, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{self, Serialize};
|
use serde::{self, Serialize};
|
||||||
|
|
||||||
use crate::database::models::{DocumentVersion, DocumentVersionWithoutContent, VaultUpdateId};
|
use crate::app_state::database::models::{
|
||||||
|
DocumentVersion, DocumentVersionWithoutContent, VaultUpdateId,
|
||||||
|
};
|
||||||
|
|
||||||
/// Response to a ping request.
|
/// Response to a ping request.
|
||||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,15 @@ use serde::Deserialize;
|
||||||
use sync_lib::{base64_to_bytes, is_file_type_mergable, merge};
|
use sync_lib::{base64_to_bytes, is_file_type_mergable, merge};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
app_state::AppState,
|
|
||||||
auth::auth,
|
auth::auth,
|
||||||
requests::{UpdateDocumentVersion, UpdateDocumentVersionMultipart},
|
requests::{UpdateDocumentVersion, UpdateDocumentVersionMultipart},
|
||||||
responses::DocumentUpdateResponse,
|
responses::DocumentUpdateResponse,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
database::models::{DocumentId, StoredDocumentVersion, VaultId, VaultUpdateId},
|
app_state::{
|
||||||
|
AppState,
|
||||||
|
database::models::{DocumentId, StoredDocumentVersion, VaultId, VaultUpdateId},
|
||||||
|
},
|
||||||
errors::{SyncServerError, client_error, not_found_error, server_error},
|
errors::{SyncServerError, client_error, not_found_error, server_error},
|
||||||
utils::{deduped_file_paths, sanitize_path},
|
utils::{deduped_file_paths, sanitize_path},
|
||||||
};
|
};
|
||||||
|
|
@ -83,7 +85,7 @@ pub async fn update_document_json(
|
||||||
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
|
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
|
||||||
async fn internal_update_document(
|
async fn internal_update_document(
|
||||||
auth_header: Authorization<Bearer>,
|
auth_header: Authorization<Bearer>,
|
||||||
mut state: AppState,
|
state: AppState,
|
||||||
vault_id: VaultId,
|
vault_id: VaultId,
|
||||||
document_id: DocumentId,
|
document_id: DocumentId,
|
||||||
parent_version_id: VaultUpdateId,
|
parent_version_id: VaultUpdateId,
|
||||||
|
|
@ -216,6 +218,11 @@ async fn internal_update_document(
|
||||||
.context("Failed to commit successful transaction")
|
.context("Failed to commit successful transaction")
|
||||||
.map_err(server_error)?;
|
.map_err(server_error)?;
|
||||||
|
|
||||||
|
state
|
||||||
|
.broadcasts
|
||||||
|
.send(vault_id, new_version.clone().into())
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Json(if is_different_from_request_content {
|
Ok(Json(if is_different_from_request_content {
|
||||||
DocumentUpdateResponse::MergingUpdate(new_version.into())
|
DocumentUpdateResponse::MergingUpdate(new_version.into())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue