mirror of
https://github.com/euzu/tuliprox.git
synced 2026-09-29 04:22:33 +02:00
* No template file not found error message * Setup wizard improvmenets * path improvements * staged input fix * path improvements * Provider dns resolved ips now writing to a file instead of source.yml * Playlist update hard kill after 1h * matadata update tmdb fix * Web UI fixes * GeoIp update schedule * batch:// prefix for aliases
54 lines
2.1 KiB
Rust
54 lines
2.1 KiB
Rust
use crate::{
|
|
api::model::{EventManager, EventMessage, UpdateGuardPermit},
|
|
library::LibraryProcessor,
|
|
model::{LibraryConfig, MetadataUpdateConfig},
|
|
};
|
|
use log::{error, info};
|
|
use shared::model::{LibraryScanSummary, LibraryScanSummaryStatus};
|
|
use std::sync::Arc;
|
|
|
|
pub(crate) struct LibraryScanTaskOptions {
|
|
pub force_rescan: bool,
|
|
pub message_prefix: &'static str,
|
|
pub storage_dir: String,
|
|
}
|
|
|
|
pub(crate) fn spawn_library_scan(
|
|
event_manager: Arc<EventManager>,
|
|
lib_config: LibraryConfig,
|
|
metadata_update_config: Option<MetadataUpdateConfig>,
|
|
client: reqwest::Client,
|
|
options: LibraryScanTaskOptions,
|
|
permit: UpdateGuardPermit,
|
|
) {
|
|
let LibraryScanTaskOptions { force_rescan, message_prefix, storage_dir } = options;
|
|
let prefix = message_prefix.to_string();
|
|
tokio::spawn(async move {
|
|
let _permit = permit;
|
|
let processor = LibraryProcessor::new(lib_config, metadata_update_config.as_ref(), client, &storage_dir);
|
|
match processor.scan(force_rescan).await {
|
|
Ok(result) => {
|
|
info!("{prefix}Library scan completed successfully");
|
|
let response = LibraryScanSummary {
|
|
status: LibraryScanSummaryStatus::Success,
|
|
message: format!(
|
|
"{prefix}Scan completed: {} files scanned, {} added, {} updated, {} removed",
|
|
result.files_scanned, result.files_added, result.files_updated, result.files_removed
|
|
),
|
|
result: Some(result),
|
|
};
|
|
let _ = event_manager.send_event(EventMessage::LibraryScanProgress(response));
|
|
}
|
|
Err(err) => {
|
|
error!("{prefix}Library scan failed: {err}");
|
|
let response = LibraryScanSummary {
|
|
status: LibraryScanSummaryStatus::Error,
|
|
message: format!("{prefix}Scan failed: {err}"),
|
|
result: None,
|
|
};
|
|
let _ = event_manager.send_event(EventMessage::LibraryScanProgress(response));
|
|
}
|
|
}
|
|
});
|
|
}
|