Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I28cf5b7b7cff8e90e123d624d97cf9656a6a6964
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
use axum::{Json, extract::State};
|
|
|
|
use crate::{
|
|
dto::{ScanJobResponse, ScanRequest, ScanStatusResponse},
|
|
error::ApiError,
|
|
state::AppState,
|
|
};
|
|
|
|
/// Trigger a scan as a background job. Returns the job ID immediately.
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/scan",
|
|
tag = "scan",
|
|
request_body = ScanRequest,
|
|
responses(
|
|
(status = 200, description = "Scan job submitted", body = ScanJobResponse),
|
|
(status = 401, description = "Unauthorized"),
|
|
(status = 403, description = "Forbidden"),
|
|
(status = 500, description = "Internal server error"),
|
|
),
|
|
security(("bearer_auth" = []))
|
|
)]
|
|
pub async fn trigger_scan(
|
|
State(state): State<AppState>,
|
|
Json(req): Json<ScanRequest>,
|
|
) -> Result<Json<ScanJobResponse>, ApiError> {
|
|
let kind = pinakes_core::jobs::JobKind::Scan { path: req.path };
|
|
let job_id = state.job_queue.submit(kind).await;
|
|
Ok(Json(ScanJobResponse {
|
|
job_id: job_id.to_string(),
|
|
}))
|
|
}
|
|
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/scan/status",
|
|
tag = "scan",
|
|
responses(
|
|
(status = 200, description = "Scan status", body = ScanStatusResponse),
|
|
(status = 401, description = "Unauthorized"),
|
|
),
|
|
security(("bearer_auth" = []))
|
|
)]
|
|
pub async fn scan_status(
|
|
State(state): State<AppState>,
|
|
) -> Json<ScanStatusResponse> {
|
|
let snapshot = state.scan_progress.snapshot();
|
|
let error_count = snapshot.errors.len();
|
|
Json(ScanStatusResponse {
|
|
scanning: snapshot.scanning,
|
|
files_found: snapshot.files_found,
|
|
files_processed: snapshot.files_processed,
|
|
error_count,
|
|
errors: snapshot.errors,
|
|
})
|
|
}
|