2026-04-04 01:40:24 +08:00
|
|
|
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;
|
2026-04-03 14:59:58 +08:00
|
|
|
|
|
|
|
|
pub(super) async fn maybe_handle(
|
|
|
|
|
state: &AppState,
|
|
|
|
|
request_context: &GatewayPublicRequestContext,
|
2026-04-04 01:40:24 +08:00
|
|
|
_request_body: Option<&Bytes>,
|
2026-04-03 14:59:58 +08:00
|
|
|
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)
|
|
|
|
|
}
|