You've already forked AstralRinth
forked from didirus/AstralRinth
* Update some Labrinth dependencies * Update some Labrinth dependencies * Update some Labrinth dependencies * Update zip in Labrinth * Update itertools in Labrinth * Update validator in labrinth * Update thiserror in labrinth * Update rust_decimal, redis, and deadpool-redis in labrinth * Update totp-rs and spdx in labrinth * Update maxminddb and tar in labrinth * Update sentry and sentry-actix in labrinth * Update image in labrinth * Update lettre in labrinth * Update derive-new and rust_iso3166 in labrinth * Update async-stripe and json-patch in labrinth * Update clap and iana-time-zone in labrinth * Update labrinth to Rust 2024 * Cargo fmt * Just do a full cargo update * Update daedelus to Rust 2024 * Update daedelus_client to Rust 2024 * Set the formatting edition to 2024 * Fix formatting IntelliJ messed up my formatting
41 lines
1.0 KiB
Rust
41 lines
1.0 KiB
Rust
use crate::routes::{
|
|
ApiError, v2_reroute,
|
|
v3::{self, statistics::V3Stats},
|
|
};
|
|
use actix_web::{HttpResponse, get, web};
|
|
use sqlx::PgPool;
|
|
|
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
|
cfg.service(get_stats);
|
|
}
|
|
|
|
#[derive(serde::Serialize)]
|
|
pub struct V2Stats {
|
|
pub projects: Option<i64>,
|
|
pub versions: Option<i64>,
|
|
pub authors: Option<i64>,
|
|
pub files: Option<i64>,
|
|
}
|
|
|
|
#[get("statistics")]
|
|
pub async fn get_stats(
|
|
pool: web::Data<PgPool>,
|
|
) -> Result<HttpResponse, ApiError> {
|
|
let response = v3::statistics::get_stats(pool)
|
|
.await
|
|
.or_else(v2_reroute::flatten_404_error)?;
|
|
|
|
match v2_reroute::extract_ok_json::<V3Stats>(response).await {
|
|
Ok(stats) => {
|
|
let stats = V2Stats {
|
|
projects: stats.projects,
|
|
versions: stats.versions,
|
|
authors: stats.authors,
|
|
files: stats.files,
|
|
};
|
|
Ok(HttpResponse::Ok().json(stats))
|
|
}
|
|
Err(response) => Ok(response),
|
|
}
|
|
}
|