Skip to content

Commit

Permalink
Merge pull request #913 from AppFlowy-IO/improve-publish-meta
Browse files Browse the repository at this point in the history
chore: publish metadata wrapper
  • Loading branch information
speed2exe authored Oct 21, 2024
2 parents 9a4d633 + 3aabf09 commit 5502c67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 3 additions & 11 deletions libs/client-api/src/http_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ impl Client {
publish_name: &str,
) -> Result<T, AppResponseError>
where
T: serde::de::DeserializeOwned,
T: serde::de::DeserializeOwned + 'static,
{
tracing::debug!(
"get_published_collab: {} {}",
publish_namespace,
publish_name
);
let url = format!(
"{}/api/workspace/published/{}/{}",
"{}/api/workspace/v1/published/{}/{}",
self.base_url, publish_namespace, publish_name
);

Expand All @@ -312,15 +312,7 @@ impl Client {
.error_for_status()?;
log_request_id(&resp);

let txt = resp.text().await?;

if let Ok(app_err) = serde_json::from_str::<AppResponseError>(&txt) {
return Err(app_err);
}

let meta = serde_json::from_str::<T>(&txt)?;

Ok(meta)
AppResponse::<T>::from_response(resp).await?.into_data()
}

#[instrument(level = "debug", skip_all)]
Expand Down
19 changes: 18 additions & 1 deletion src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ pub fn workspace_scope() -> Scope {
.route(web::get().to(get_default_published_collab_info_meta_handler)),
)
.service(
web::resource("/published/{publish_namespace}/{publish_name}")
web::resource("/published/{publish_namespace}/{publish_name}") // Deprecated
.route(web::get().to(get_published_collab_handler)),
)
.service(
web::resource("/v1/published/{publish_namespace}/{publish_name}")
.route(web::get().to(get_v1_published_collab_handler)),
)
.service(
web::resource("/published/{publish_namespace}/{publish_name}/blob")
.route(web::get().to(get_published_collab_blob_handler)),
Expand Down Expand Up @@ -1218,6 +1222,7 @@ async fn get_default_published_collab_info_meta_handler(
))
}

/// Deprecated
async fn get_published_collab_handler(
path_param: web::Path<(String, String)>,
state: Data<AppState>,
Expand All @@ -1230,6 +1235,18 @@ async fn get_published_collab_handler(
Ok(Json(metadata))
}

async fn get_v1_published_collab_handler(
path_param: web::Path<(String, String)>,
state: Data<AppState>,
) -> Result<Json<AppResponse<serde_json::Value>>> {
let (workspace_namespace, publish_name) = path_param.into_inner();
let metadata = state
.published_collab_store
.get_collab_metadata(&workspace_namespace, &publish_name)
.await?;
Ok(Json(AppResponse::Ok().with_data(metadata)))
}

async fn get_published_collab_blob_handler(
path_param: web::Path<(String, String)>,
state: Data<AppState>,
Expand Down

0 comments on commit 5502c67

Please sign in to comment.