Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
69 lines
2.3 KiB
Rust
69 lines
2.3 KiB
Rust
use axum::{Json, extract::State};
|
|
|
|
use crate::{dto::DatabaseStatsResponse, error::ApiError, state::AppState};
|
|
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/admin/database/stats",
|
|
tag = "database",
|
|
responses(
|
|
(status = 200, description = "Database statistics", body = DatabaseStatsResponse),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 500, description = "Internal server error"),
|
|
),
|
|
security(("bearer_auth" = []))
|
|
)]
|
|
pub async fn database_stats(
|
|
State(state): State<AppState>,
|
|
) -> Result<Json<DatabaseStatsResponse>, ApiError> {
|
|
let stats = state.storage.database_stats().await?;
|
|
Ok(Json(DatabaseStatsResponse {
|
|
media_count: stats.media_count,
|
|
tag_count: stats.tag_count,
|
|
collection_count: stats.collection_count,
|
|
audit_count: stats.audit_count,
|
|
database_size_bytes: stats.database_size_bytes,
|
|
backend_name: stats.backend_name,
|
|
}))
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/admin/database/vacuum",
|
|
tag = "database",
|
|
responses(
|
|
(status = 200, description = "Database vacuumed"),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 500, description = "Internal server error"),
|
|
),
|
|
security(("bearer_auth" = []))
|
|
)]
|
|
pub async fn vacuum_database(
|
|
State(state): State<AppState>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
state.storage.vacuum().await?;
|
|
Ok(Json(serde_json::json!({"status": "ok"})))
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/admin/database/clear",
|
|
tag = "database",
|
|
responses(
|
|
(status = 200, description = "Database cleared"),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 500, description = "Internal server error"),
|
|
),
|
|
security(("bearer_auth" = []))
|
|
)]
|
|
pub async fn clear_database(
|
|
State(state): State<AppState>,
|
|
) -> Result<Json<serde_json::Value>, ApiError> {
|
|
tracing::error!("clear_database: all data is being wiped by admin request");
|
|
state.storage.clear_all_data().await?;
|
|
tracing::error!("clear_database: all data wiped successfully");
|
|
Ok(Json(serde_json::json!({"status": "ok"})))
|
|
}
|