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:
@@ -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())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,43 +309,39 @@ 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 item_id <= 0 {
|
||||||
if id <= 0 {
|
warn!("Invalid item ID {} from {}", item_id, addr);
|
||||||
warn!("Invalid item ID {} from {}", 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 {
|
||||||
Ok(content) => {
|
Ok(content) => {
|
||||||
let response = ApiResponse {
|
let response = ApiResponse {
|
||||||
success: true,
|
success: true,
|
||||||
data: Some(content),
|
data: Some(content),
|
||||||
error: None,
|
error: None,
|
||||||
};
|
};
|
||||||
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,
|
||||||
error: Some(format!("Failed to retrieve content: {}", e)),
|
error: Some(format!("Failed to retrieve content: {}", e)),
|
||||||
};
|
};
|
||||||
Ok(Json(response))
|
Ok(Json(response))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Err(StatusCode::NOT_FOUND)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(StatusCode::BAD_REQUEST)
|
Err(StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,38 +435,34 @@ 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 item_id <= 0 {
|
||||||
if id <= 0 {
|
warn!("Invalid item ID {} from {}", item_id, addr);
|
||||||
warn!("Invalid item ID {} from {}", 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 {
|
||||||
Ok((content, mime_type)) => {
|
Ok((content, mime_type)) => {
|
||||||
let mut response = content.into_response();
|
let mut response = content.into_response();
|
||||||
response.headers_mut().insert(
|
response.headers_mut().insert(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
mime_type.parse().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
mime_type.parse().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||||
);
|
);
|
||||||
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 {
|
|
||||||
Err(StatusCode::NOT_FOUND)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(StatusCode::BAD_REQUEST)
|
Err(StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,34 +612,30 @@ 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()
|
||||||
.map(|m| (m.name, m.value))
|
.map(|m| (m.name, m.value))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let response = ApiResponse {
|
let response = ApiResponse {
|
||||||
success: true,
|
success: true,
|
||||||
data: Some(item_meta),
|
data: Some(item_meta),
|
||||||
error: None,
|
error: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Json(response))
|
Ok(Json(response))
|
||||||
} else {
|
|
||||||
Err(StatusCode::NOT_FOUND)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Err(StatusCode::BAD_REQUEST)
|
Err(StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user