fix: resolve compilation errors in API paths and file descriptor handling
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -161,7 +161,7 @@ pub async fn handle_post_item(
|
||||
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/item/{id}",
|
||||
path = "/api/item/{item_id}",
|
||||
responses(
|
||||
(status = 200, description = "Successfully deleted item", body = ApiResponse<()>),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
@@ -169,7 +169,7 @@ pub async fn handle_post_item(
|
||||
(status = 500, description = "Internal server error")
|
||||
),
|
||||
params(
|
||||
("id" = i64, Path, description = "ID of the item to delete")
|
||||
("item_id" = i64, Path, description = "ID of the item to delete")
|
||||
),
|
||||
security(
|
||||
("bearerAuth" = [])
|
||||
@@ -177,29 +177,29 @@ pub async fn handle_post_item(
|
||||
)]
|
||||
pub async fn handle_delete_item(
|
||||
State(state): State<AppState>,
|
||||
Path(id): Path<i64>,
|
||||
Path(item_id): Path<i64>,
|
||||
headers: HeaderMap,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
) -> Result<Json<ApiResponse<()>>, StatusCode> {
|
||||
if !check_auth(&headers, &state.password) {
|
||||
warn!("Unauthorized request to DELETE /api/item/{} from {}", id, addr);
|
||||
warn!("Unauthorized request to DELETE /api/item/{} from {}", item_id, addr);
|
||||
return Err(StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
// Validate that item ID is positive to prevent path traversal issues
|
||||
if id <= 0 {
|
||||
warn!("Invalid item ID {} from {}", id, addr);
|
||||
if item_id <= 0 {
|
||||
warn!("Invalid item ID {} from {}", item_id, addr);
|
||||
return Err(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
let mut conn = state.db.lock().await;
|
||||
|
||||
if let Some(item) = db::get_item(&mut *conn, id).map_err(|e| {
|
||||
warn!("Failed to get item {} for deletion: {}", id, e);
|
||||
if let Some(item) = db::get_item(&mut *conn, item_id).map_err(|e| {
|
||||
warn!("Failed to get item {} for deletion: {}", item_id, e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})? {
|
||||
db::delete_item(&mut *conn, item).map_err(|e| {
|
||||
warn!("Failed to delete item {}: {}", id, e);
|
||||
warn!("Failed to delete item {}: {}", item_id, e);
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user