2026-04-09 00:10:38 +08:00
|
|
|
use super::super::errors::build_internal_control_error_response;
|
2026-04-07 12:15:19 +08:00
|
|
|
use crate::handlers::admin::provider::shared::paths::admin_provider_oauth_batch_import_task_path;
|
2026-04-09 00:10:38 +08:00
|
|
|
use crate::handlers::admin::request::{AdminAppState, AdminRequestContext};
|
2026-04-07 02:50:19 +08:00
|
|
|
use crate::handlers::admin::shared::attach_admin_audit_response;
|
2026-04-09 00:10:38 +08:00
|
|
|
use crate::GatewayError;
|
2026-04-04 01:40:24 +08:00
|
|
|
use axum::{
|
|
|
|
|
body::Body,
|
|
|
|
|
http,
|
|
|
|
|
response::{IntoResponse, Response},
|
|
|
|
|
Json,
|
|
|
|
|
};
|
2026-04-03 14:59:58 +08:00
|
|
|
|
|
|
|
|
pub(super) async fn handle_admin_provider_oauth_batch_import_task_status(
|
2026-04-09 00:10:38 +08:00
|
|
|
state: &AdminAppState<'_>,
|
|
|
|
|
request_context: &AdminRequestContext<'_>,
|
2026-03-31 19:19:04 +08:00
|
|
|
) -> Result<Response<Body>, GatewayError> {
|
|
|
|
|
let Some((provider_id, task_id)) =
|
2026-04-09 00:10:38 +08:00
|
|
|
admin_provider_oauth_batch_import_task_path(request_context.path())
|
2026-03-31 19:19:04 +08:00
|
|
|
else {
|
2026-04-03 14:59:58 +08:00
|
|
|
return Ok(build_internal_control_error_response(
|
2026-03-31 19:19:04 +08:00
|
|
|
http::StatusCode::NOT_FOUND,
|
|
|
|
|
"批量导入任务不存在",
|
|
|
|
|
));
|
|
|
|
|
};
|
2026-04-09 00:10:38 +08:00
|
|
|
let payload = match state
|
|
|
|
|
.read_provider_oauth_batch_task_payload(&provider_id, &task_id)
|
|
|
|
|
.await
|
2026-03-31 19:19:04 +08:00
|
|
|
{
|
|
|
|
|
Ok(Some(payload)) => payload,
|
|
|
|
|
Ok(None) => {
|
2026-04-03 14:59:58 +08:00
|
|
|
return Ok(build_internal_control_error_response(
|
2026-03-31 19:19:04 +08:00
|
|
|
http::StatusCode::NOT_FOUND,
|
|
|
|
|
"批量导入任务不存在或已过期",
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
Err(_) => {
|
2026-04-03 14:59:58 +08:00
|
|
|
return Ok(build_internal_control_error_response(
|
2026-03-31 19:19:04 +08:00
|
|
|
http::StatusCode::SERVICE_UNAVAILABLE,
|
|
|
|
|
"provider oauth batch task redis unavailable",
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-04-05 20:23:16 +08:00
|
|
|
let status = payload
|
|
|
|
|
.get("status")
|
|
|
|
|
.and_then(serde_json::Value::as_str)
|
|
|
|
|
.map(ToOwned::to_owned)
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
let response = Json(payload).into_response();
|
|
|
|
|
Ok(match status.as_str() {
|
|
|
|
|
"completed" => attach_admin_audit_response(
|
|
|
|
|
response,
|
|
|
|
|
"admin_provider_oauth_batch_task_completed_viewed",
|
|
|
|
|
"view_provider_oauth_batch_task_terminal_state",
|
|
|
|
|
"provider_oauth_batch_task",
|
|
|
|
|
&format!("{provider_id}:{task_id}"),
|
|
|
|
|
),
|
|
|
|
|
"failed" => attach_admin_audit_response(
|
|
|
|
|
response,
|
|
|
|
|
"admin_provider_oauth_batch_task_failed_viewed",
|
|
|
|
|
"view_provider_oauth_batch_task_terminal_state",
|
|
|
|
|
"provider_oauth_batch_task",
|
|
|
|
|
&format!("{provider_id}:{task_id}"),
|
|
|
|
|
),
|
|
|
|
|
_ => response,
|
|
|
|
|
})
|
2026-03-31 19:19:04 +08:00
|
|
|
}
|