fix: resolve OpenAPI macro and file descriptor type mismatches

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-13 11:40:44 -03:00
parent 99949cf1ee
commit 6bfb5ed963
2 changed files with 86 additions and 97 deletions

View File

@@ -77,6 +77,7 @@ fn setup_diff_paths_and_compression(
fn setup_diff_pipes() -> Result<((libc::c_int, libc::c_int), (libc::c_int, libc::c_int)), anyhow::Error> { fn setup_diff_pipes() -> Result<((libc::c_int, libc::c_int), (libc::c_int, libc::c_int)), anyhow::Error> {
use nix::unistd::pipe; use nix::unistd::pipe;
use nix::Error as NixError; use nix::Error as NixError;
use std::os::fd::IntoRawFd;
// Create pipes for diff's input // Create pipes for diff's input
let (fd_a_read, fd_a_write) = pipe() let (fd_a_read, fd_a_write) = pipe()
@@ -84,7 +85,7 @@ fn setup_diff_pipes() -> Result<((libc::c_int, libc::c_int), (libc::c_int, libc:
let (fd_b_read, fd_b_write) = pipe() let (fd_b_read, fd_b_write) = pipe()
.map_err(|e: NixError| anyhow::anyhow!("Failed to create pipe B: {}", e))?; .map_err(|e: NixError| anyhow::anyhow!("Failed to create pipe B: {}", e))?;
Ok(((fd_a_read, fd_a_write), (fd_b_read, fd_b_write))) Ok(((fd_a_read.into_raw_fd(), fd_a_write.into_raw_fd()), (fd_b_read.into_raw_fd(), fd_b_write.into_raw_fd())))
} }

View File

@@ -169,7 +169,7 @@ pub async fn handle_post_item(
(status = 500, description = "Internal server error") (status = 500, description = "Internal server error")
), ),
params( params(
("item_id" = String, Path, description = "ID of the item to delete") ("item_id" = i64, Path, description = "ID of the item to delete")
), ),
security( security(
("bearerAuth" = []) ("bearerAuth" = [])
@@ -292,7 +292,7 @@ pub async fn handle_get_item_latest(
(status = 500, description = "Internal server error") (status = 500, description = "Internal server error")
), ),
params( params(
("item_id" = String, Path, description = "ID of the item to retrieve") ("item_id" = i64, Path, description = "ID of the item to retrieve")
), ),
security( security(
("bearerAuth" = []) ("bearerAuth" = [])
@@ -300,7 +300,7 @@ pub async fn handle_get_item_latest(
)] )]
pub async fn handle_get_item( pub async fn handle_get_item(
State(state): State<AppState>, State(state): State<AppState>,
Path(item_id): Path<String>, Path(item_id): Path<i64>,
headers: HeaderMap, headers: HeaderMap,
ConnectInfo(addr): ConnectInfo<SocketAddr>, ConnectInfo(addr): ConnectInfo<SocketAddr>,
) -> Result<Json<ApiResponse<String>>, StatusCode> { ) -> Result<Json<ApiResponse<String>>, StatusCode> {
@@ -309,17 +309,16 @@ pub async fn handle_get_item(
return Err(StatusCode::UNAUTHORIZED); return Err(StatusCode::UNAUTHORIZED);
} }
if let Ok(id) = item_id.parse::<i64>() {
// Validate that item ID is positive to prevent path traversal issues // Validate that item ID is positive to prevent path traversal issues
if id <= 0 { if item_id <= 0 {
warn!("Invalid item ID {} from {}", id, addr); warn!("Invalid item ID {} from {}", item_id, addr);
return Err(StatusCode::BAD_REQUEST); return Err(StatusCode::BAD_REQUEST);
} }
let mut conn = state.db.lock().await; let mut conn = state.db.lock().await;
if let Some(item) = db::get_item(&mut *conn, id).map_err(|e| { if let Some(item) = db::get_item(&mut *conn, item_id).map_err(|e| {
warn!("Failed to get item {} for content: {}", id, e); warn!("Failed to get item {} for content: {}", item_id, e);
StatusCode::INTERNAL_SERVER_ERROR StatusCode::INTERNAL_SERVER_ERROR
})? { })? {
match get_item_content(&item, &state.data_dir).await { match get_item_content(&item, &state.data_dir).await {
@@ -332,7 +331,7 @@ pub async fn handle_get_item(
Ok(Json(response)) Ok(Json(response))
} }
Err(e) => { Err(e) => {
warn!("Failed to get content for item {}: {}", id, e); warn!("Failed to get content for item {}: {}", item_id, e);
let response = ApiResponse::<String> { let response = ApiResponse::<String> {
success: false, success: false,
data: None, data: None,
@@ -344,9 +343,6 @@ pub async fn handle_get_item(
} else { } else {
Err(StatusCode::NOT_FOUND) Err(StatusCode::NOT_FOUND)
} }
} else {
Err(StatusCode::BAD_REQUEST)
}
} }
#[utoipa::path( #[utoipa::path(
@@ -422,7 +418,7 @@ pub async fn handle_get_item_latest_content(
(status = 500, description = "Internal server error") (status = 500, description = "Internal server error")
), ),
params( params(
("item_id" = String, Path, description = "ID of the item to retrieve") ("item_id" = i64, Path, description = "ID of the item to retrieve")
), ),
security( security(
("bearerAuth" = []) ("bearerAuth" = [])
@@ -430,7 +426,7 @@ pub async fn handle_get_item_latest_content(
)] )]
pub async fn handle_get_item_content( pub async fn handle_get_item_content(
State(state): State<AppState>, State(state): State<AppState>,
Path(item_id): Path<String>, Path(item_id): Path<i64>,
headers: HeaderMap, headers: HeaderMap,
ConnectInfo(addr): ConnectInfo<SocketAddr>, ConnectInfo(addr): ConnectInfo<SocketAddr>,
) -> Result<Response, StatusCode> { ) -> Result<Response, StatusCode> {
@@ -439,17 +435,16 @@ pub async fn handle_get_item_content(
return Err(StatusCode::UNAUTHORIZED); return Err(StatusCode::UNAUTHORIZED);
} }
if let Ok(id) = item_id.parse::<i64>() {
// Validate that item ID is positive to prevent path traversal issues // Validate that item ID is positive to prevent path traversal issues
if id <= 0 { if item_id <= 0 {
warn!("Invalid item ID {} from {}", id, addr); warn!("Invalid item ID {} from {}", item_id, addr);
return Err(StatusCode::BAD_REQUEST); return Err(StatusCode::BAD_REQUEST);
} }
let mut conn = state.db.lock().await; let mut conn = state.db.lock().await;
if let Some(item) = db::get_item(&mut *conn, id).map_err(|e| { if let Some(item) = db::get_item(&mut *conn, item_id).map_err(|e| {
warn!("Failed to get item {} for content: {}", id, e); warn!("Failed to get item {} for content: {}", item_id, e);
StatusCode::INTERNAL_SERVER_ERROR StatusCode::INTERNAL_SERVER_ERROR
})? { })? {
match get_item_raw_content(&item, &state.data_dir, &mut *conn).await { match get_item_raw_content(&item, &state.data_dir, &mut *conn).await {
@@ -462,16 +457,13 @@ pub async fn handle_get_item_content(
Ok(response) Ok(response)
} }
Err(e) => { Err(e) => {
warn!("Failed to get raw content for item {}: {}", id, e); warn!("Failed to get raw content for item {}: {}", item_id, e);
Err(StatusCode::INTERNAL_SERVER_ERROR) Err(StatusCode::INTERNAL_SERVER_ERROR)
} }
} }
} else { } else {
Err(StatusCode::NOT_FOUND) Err(StatusCode::NOT_FOUND)
} }
} else {
Err(StatusCode::BAD_REQUEST)
}
} }
async fn get_item_content(item: &db::Item, data_dir: &PathBuf) -> Result<String> { async fn get_item_content(item: &db::Item, data_dir: &PathBuf) -> Result<String> {
@@ -603,7 +595,7 @@ pub async fn handle_get_item_latest_meta(
(status = 500, description = "Internal server error") (status = 500, description = "Internal server error")
), ),
params( params(
("item_id" = String, Path, description = "ID of the item to retrieve metadata for") ("item_id" = i64, Path, description = "ID of the item to retrieve metadata for")
), ),
security( security(
("bearerAuth" = []) ("bearerAuth" = [])
@@ -611,7 +603,7 @@ pub async fn handle_get_item_latest_meta(
)] )]
pub async fn handle_get_item_meta( pub async fn handle_get_item_meta(
State(state): State<AppState>, State(state): State<AppState>,
Path(item_id): Path<String>, Path(item_id): Path<i64>,
headers: HeaderMap, headers: HeaderMap,
ConnectInfo(addr): ConnectInfo<SocketAddr>, ConnectInfo(addr): ConnectInfo<SocketAddr>,
) -> Result<Json<ApiResponse<HashMap<String, String>>>, StatusCode> { ) -> Result<Json<ApiResponse<HashMap<String, String>>>, StatusCode> {
@@ -620,16 +612,15 @@ pub async fn handle_get_item_meta(
return Err(StatusCode::UNAUTHORIZED); return Err(StatusCode::UNAUTHORIZED);
} }
if let Ok(id) = item_id.parse::<i64>() {
let mut conn = state.db.lock().await; let mut conn = state.db.lock().await;
if let Some(item) = db::get_item(&mut *conn, id).map_err(|e| { if let Some(item) = db::get_item(&mut *conn, item_id).map_err(|e| {
warn!("Failed to get item {} for meta: {}", id, e); warn!("Failed to get item {} for meta: {}", item_id, e);
StatusCode::INTERNAL_SERVER_ERROR StatusCode::INTERNAL_SERVER_ERROR
})? { })? {
let item_meta = db::get_item_meta(&mut *conn, &item) let item_meta = db::get_item_meta(&mut *conn, &item)
.map_err(|e| { .map_err(|e| {
warn!("Failed to get metadata for item {}: {}", id, e); warn!("Failed to get metadata for item {}: {}", item_id, e);
StatusCode::INTERNAL_SERVER_ERROR StatusCode::INTERNAL_SERVER_ERROR
})? })?
.into_iter() .into_iter()
@@ -646,8 +637,5 @@ pub async fn handle_get_item_meta(
} else { } else {
Err(StatusCode::NOT_FOUND) Err(StatusCode::NOT_FOUND)
} }
} else {
Err(StatusCode::BAD_REQUEST)
}
} }