wowlab_sentinel/http/routes/
chunks.rs1use std::sync::Arc;
4
5use axum::{Extension, Json, Router, body::Bytes, extract::State, routing::post};
6use prost::Message;
7use wowlab_common::node_http::NodeChunkCompletionResponse;
8use wowlab_types::proto;
9
10use crate::{
11 http::{
12 api_error::ApiError,
13 auth::VerifiedNode,
14 services::chunks::{CompletionInput, completion_workflow},
15 },
16 state::ServerState,
17};
18
19pub(super) fn router() -> Router<Arc<ServerState>> {
20 Router::new().route("/chunks/complete", post(complete))
21}
22
23async fn complete(
24 State(state): State<Arc<ServerState>>,
25 Extension(node): Extension<VerifiedNode>,
26 body: Bytes,
27) -> Result<Json<NodeChunkCompletionResponse>, ApiError> {
28 let completion = proto::BatchChunkCompletion::decode(body.as_ref()).map_err(|source| {
29 tracing::warn!(error = %source, "Failed to decode BatchChunkCompletion");
30
31 ApiError::invalid_protobuf(source)
32 })?;
33 let input = CompletionInput::parse(&node.public_key, &completion)?;
34 let response = completion_workflow(&state).complete(input).await?;
35
36 Ok(Json(response))
37}