Files
Aether/apps/aether-gateway/src/handlers/admin/provider_models/available_source.rs
T

47 lines
1.6 KiB
Rust
Raw Normal View History

use super::super::build_admin_provider_available_source_models_payload;
use crate::gateway::handlers::admin_provider_available_source_models_path;
use crate::gateway::{AppState, GatewayControlDecision, GatewayError, GatewayPublicRequestContext};
use axum::{
body::{Body, Bytes},
http,
response::{IntoResponse, Response},
Json,
};
use serde_json::json;
pub(super) async fn maybe_handle(
state: &AppState,
request_context: &GatewayPublicRequestContext,
_request_body: Option<&Bytes>,
decision: &GatewayControlDecision,
) -> Result<Option<Response<Body>>, GatewayError> {
if decision.route_family.as_deref() == Some("provider_models_manage")
&& decision.route_kind.as_deref() == Some("available_source_models")
&& request_context.request_method == http::Method::GET
{
let Some(provider_id) =
admin_provider_available_source_models_path(&request_context.request_path)
else {
return Ok(Some(
(
http::StatusCode::NOT_FOUND,
Json(json!({ "detail": "Provider 不存在" })),
)
.into_response(),
));
};
return Ok(Some(
match build_admin_provider_available_source_models_payload(state, &provider_id).await {
Some(payload) => Json(payload).into_response(),
None => (
http::StatusCode::NOT_FOUND,
Json(json!({ "detail": format!("Provider {provider_id} 不存在") })),
)
.into_response(),
},
));
}
Ok(None)
}