Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I67206fd813d514f8903041eea0a4cd266a6a6964
33 lines
930 B
Rust
33 lines
930 B
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.
|
|
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(),
|
|
}))
|
|
}
|
|
|
|
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,
|
|
})
|
|
}
|