diff --git a/src/modes/server/api/item.rs b/src/modes/server/api/item.rs index af3a6e4..f4c4124 100644 --- a/src/modes/server/api/item.rs +++ b/src/modes/server/api/item.rs @@ -1,5 +1,5 @@ use axum::{ - extract::{Path, Query, State}, + extract::{Path, Query, State, Host}, http::{StatusCode}, response::{Json, Response}, http::header, @@ -75,7 +75,11 @@ pub async fn handle_list_items( .map(|item_with_meta| { let item_id = item_with_meta.item.id.unwrap_or(0); let item_tags: Vec = item_with_meta.tags.iter().map(|t| t.name.clone()).collect(); - let item_meta = item_with_meta.meta_as_map(); + let mut item_meta = item_with_meta.meta_as_map(); + // Add content_url to metadata + // Note: We don't have access to the host here, so we'll use a placeholder + // The user may need to provide the base URL through AppState + item_meta.insert("content_url".to_string(), format!("/api/item/{}/content", item_id)); ItemInfo { id: item_id, @@ -577,6 +581,7 @@ async fn stream_item_content_response_with_metadata( )] pub async fn handle_get_item_latest_meta( State(state): State, + Host(host): Host, Query(params): Query, ) -> Result>>, StatusCode> { let tags: Vec = params @@ -595,7 +600,11 @@ pub async fn handle_get_item_latest_meta( match item_service.find_item(vec![], tags, HashMap::new()).await { Ok(item_with_meta) => { - let item_meta = item_with_meta.meta_as_map(); + let mut item_meta = item_with_meta.meta_as_map(); + // Add content_url to metadata + if let Some(item_id) = item_with_meta.item.id { + item_meta.insert("content_url".to_string(), format!("http://{}/api/item/{}/content", host, item_id)); + } let response = ApiResponse { success: true, @@ -636,6 +645,7 @@ pub async fn handle_get_item_latest_meta( )] pub async fn handle_get_item_meta( State(state): State, + Host(host): Host, Path(item_id): Path, ) -> Result>>, StatusCode> { let item_service = AsyncItemService::new( @@ -648,7 +658,9 @@ pub async fn handle_get_item_meta( match item_service.get_item(item_id).await { Ok(item_with_meta) => { - let item_meta = item_with_meta.meta_as_map(); + let mut item_meta = item_with_meta.meta_as_map(); + // Add content_url to metadata + item_meta.insert("content_url".to_string(), format!("http://{}/api/item/{}/content", host, item_id)); let response = ApiResponse { success: true,