From 9ee04b8958725852b47dc476a587f79a85141649 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Mon, 21 Oct 2024 12:48:02 +0800 Subject: [PATCH] chore: publish metadata wrapper --- libs/client-api/src/http_publish.rs | 14 +++----------- src/api/workspace.rs | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libs/client-api/src/http_publish.rs b/libs/client-api/src/http_publish.rs index eb36cc4b..bcc4bc18 100644 --- a/libs/client-api/src/http_publish.rs +++ b/libs/client-api/src/http_publish.rs @@ -292,7 +292,7 @@ impl Client { publish_name: &str, ) -> Result where - T: serde::de::DeserializeOwned, + T: serde::de::DeserializeOwned + 'static, { tracing::debug!( "get_published_collab: {} {}", @@ -300,7 +300,7 @@ impl Client { publish_name ); let url = format!( - "{}/api/workspace/published/{}/{}", + "{}/v1/api/workspace/published/{}/{}", self.base_url, publish_namespace, publish_name ); @@ -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::(&txt) { - return Err(app_err); - } - - let meta = serde_json::from_str::(&txt)?; - - Ok(meta) + AppResponse::::from_response(resp).await?.into_data() } #[instrument(level = "debug", skip_all)] diff --git a/src/api/workspace.rs b/src/api/workspace.rs index b5939524..6c5079ef 100644 --- a/src/api/workspace.rs +++ b/src/api/workspace.rs @@ -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)), @@ -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, @@ -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, +) -> Result>> { + 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,