chore: publish metadata wrapper

This commit is contained in:
Zack Fu Zi Xiang 2024-10-21 12:48:02 +08:00
parent 9a4d633dd3
commit 9ee04b8958
No known key found for this signature in database
2 changed files with 21 additions and 12 deletions

View File

@ -292,7 +292,7 @@ impl Client {
publish_name: &str,
) -> Result<T, AppResponseError>
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::<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)]

View File

@ -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<AppState>,
@ -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>,