Skip to main content

lean_ctx/proxy/
quality_lab_api.rs

1//! POST /v1/quality-lab — run Quality Lab analysis on a text pair.
2
3use axum::Json;
4use axum::response::{IntoResponse, Response};
5use serde::{Deserialize, Serialize};
6
7use crate::core::quality_lab::orchestrator::{QualityLabReport, run_quality_lab};
8
9#[derive(Deserialize)]
10pub(crate) struct QualityLabRequest {
11    #[serde(default)]
12    pub original: String,
13    #[serde(default)]
14    pub compressed: String,
15    #[serde(default = "default_ext")]
16    pub ext: String,
17}
18
19fn default_ext() -> String {
20    "rs".to_string()
21}
22
23#[derive(Serialize)]
24pub(crate) struct QualityLabResponse {
25    pub report: QualityLabReport,
26}
27
28pub(crate) async fn handler(Json(req): Json<QualityLabRequest>) -> Response {
29    let report = run_quality_lab(&req.original, &req.compressed, &req.ext);
30
31    Json(QualityLabResponse { report }).into_response()
32}
33
34pub(crate) async fn handler_get() -> Response {
35    let report = run_quality_lab("", "", "");
36    Json(QualityLabResponse { report }).into_response()
37}