Skip to content

Commit

Permalink
feat: api to get collab as json
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Feb 19, 2025
1 parent 316d058 commit d131e91
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/shared-entity/src/dto/workspace_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pub struct EmbeddedCollabQuery {
pub object_id: String,
}

#[derive(Debug, Clone, Serialize)]
pub struct CollabJsonResponse {
pub collab: serde_json::Value,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollabResponse {
#[serde(flatten)]
Expand Down
42 changes: 42 additions & 0 deletions src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::biz;
use crate::biz::collab::ops::{
get_user_favorite_folder_views, get_user_recent_folder_views, get_user_trash_folder_views,
};
use crate::biz::collab::utils::collab_from_doc_state;
use crate::biz::user::user_verify::verify_token;
use crate::biz::workspace;
use crate::biz::workspace::ops::{
Expand Down Expand Up @@ -140,6 +141,10 @@ pub fn workspace_scope() -> Scope {
web::resource("/v1/{workspace_id}/collab/{object_id}")
.route(web::get().to(v1_get_collab_handler)),
)
.service(
web::resource("/v1/{workspace_id}/collab/{object_id}/json")
.route(web::get().to(get_collab_json_handler)),
)
.service(
web::resource("/v1/{workspace_id}/collab/{object_id}/full-sync")
.route(web::post().to(collab_full_sync_handler)),
Expand Down Expand Up @@ -1048,6 +1053,43 @@ async fn v1_get_collab_handler(
Ok(Json(AppResponse::Ok().with_data(resp)))
}

async fn get_collab_json_handler(
user_uuid: UserUuid,
path: web::Path<(String, String)>,
query: web::Query<CollabTypeParam>,
state: Data<AppState>,
) -> Result<Json<AppResponse<CollabJsonResponse>>> {
let (workspace_id, object_id) = path.into_inner();
let collab_type = query.into_inner().collab_type;
let uid = state
.user_cache
.get_user_uid(&user_uuid)
.await
.map_err(AppResponseError::from)?;

let param = QueryCollabParams {
workspace_id,
inner: QueryCollab {
object_id: object_id.clone(),
collab_type,
},
};

let doc_state = state
.collab_access_control_storage
.get_encode_collab(GetCollabOrigin::User { uid }, param, true)
.await
.map_err(AppResponseError::from)?
.doc_state;
let collab = collab_from_doc_state(doc_state.to_vec(), &object_id)?;

let resp = CollabJsonResponse {
collab: collab.to_json_value(),
};

Ok(Json(AppResponse::Ok().with_data(resp)))
}

#[instrument(level = "debug", skip_all)]
async fn post_web_update_handler(
user_uuid: UserUuid,
Expand Down

0 comments on commit d131e91

Please sign in to comment.