(
State(state): State<AppState>,
headers: HeaderMap,
Path(server_id): Path<String>,
)
| 600 | match state.service.mod_artifact_stream(&mod_id).await { |
| 601 | Ok(Some((size, stream))) => { |
| 602 | // Stream the artifact straight from the store — never buffer the whole file. |
| 603 | let headers = [ |
| 604 | (CONTENT_TYPE, "application/octet-stream".to_string()), |
| 605 | ( |
| 606 | CONTENT_DISPOSITION, |
| 607 | format!("attachment; filename=\"{mod_id}.pbo\""), |
| 608 | ), |
| 609 | (CONTENT_LENGTH, size.to_string()), |
| 610 | ]; |
| 611 | (headers, Body::from_stream(stream)).into_response() |
| 612 | } |
| 613 | Ok(None) => StatusCode::NOT_FOUND.into_response(), |
| 614 | Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | async fn read_text_field( |
| 619 | field: axum::extract::multipart::Field<'_>, |
| 620 | ) -> Result<String, (StatusCode, String)> { |
| 621 | field |
| 622 | .text() |
| 623 | .await |
| 624 | .map_err(|error| (StatusCode::BAD_REQUEST, error.to_string())) |
| 625 | } |
| 626 | |
| 627 | #[utoipa::path( |
| 628 | delete, |
| 629 | path = "/v1/servers/{serverId}", |
| 630 | params( |
| 631 | ("serverId" = String, Path, description = "Server identifier") |
| 632 | ), |
| 633 | responses( |
| 634 | (status = 204, description = "Server removed"), |
| 635 | (status = 404, description = "Server not found") |
| 636 | ) |
| 637 | )] |
| 638 | async fn unregister_server( |
| 639 | State(state): State<AppState>, |
| 640 | headers: HeaderMap, |
| 641 | Path(server_id): Path<String>, |
| 642 | ) -> Result<StatusCode, (StatusCode, String)> { |
| 643 | // Only the owning IP may unregister its server (server_id is "<ip>:<port>"). |
| 644 | if let Some(ip) = caller_client_ip(&state, &headers) { |
| 645 | let owner_ip = server_id |
| 646 | .rsplit_once(':') |
| 647 | .map_or(server_id.as_str(), |(host, _)| host); |
| 648 | if owner_ip != ip { |
| 649 | return Err(( |
| 650 | StatusCode::FORBIDDEN, |
nothing calls this directly
no test coverage detected