feat: add content_url to metadata responses

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-29 11:46:50 -03:00
parent 7b518eb2e9
commit aa00bb134b

View File

@@ -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<String> = 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<AppState>,
Host(host): Host,
Query(params): Query<TagsQuery>,
) -> Result<Json<ApiResponse<HashMap<String, String>>>, StatusCode> {
let tags: Vec<String> = 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<AppState>,
Host(host): Host,
Path(item_id): Path<i64>,
) -> Result<Json<ApiResponse<HashMap<String, String>>>, 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,