refactor: Phase A — extraction des helpers partagés et micro-fixes
- Centralise remap_libraries_path/unmap_libraries_path dans crates/core/paths.rs (supprime 4 copies dupliquées dans API + indexer) - Centralise mode_to_interval_minutes/validate_schedule_mode dans crates/core/schedule.rs (remplace 8 match blocks + 4 validations inline) - Ajoute helpers env_or<T>/env_string_or dans config.rs, utilise ThumbnailConfig::default() comme base dans from_env() (élimine la duplication des valeurs par défaut) - Supprime std::mem::take inutile dans books.rs - Cible #[allow(dead_code)] sur le champ plutôt que le struct (metadata.rs) - Remplace eprintln! par tracing::warn! dans parsers - Fix clippy boolean logic bug dans prowlarr.rs 10 nouveaux tests unitaires (paths + schedule) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use sqlx::{PgPool, Row};
|
||||
use stripstream_core::schedule::mode_to_interval_minutes;
|
||||
use tracing::info;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -45,12 +46,7 @@ pub async fn check_and_schedule_auto_scans(pool: &PgPool) -> Result<()> {
|
||||
.await?;
|
||||
|
||||
// Update next_scan_at
|
||||
let interval_minutes = match scan_mode.as_str() {
|
||||
"hourly" => 60,
|
||||
"daily" => 1440,
|
||||
"weekly" => 10080,
|
||||
_ => 1440, // default daily
|
||||
};
|
||||
let interval_minutes = mode_to_interval_minutes(&scan_mode);
|
||||
|
||||
sqlx::query(
|
||||
"UPDATE libraries SET last_scan_at = NOW(), next_scan_at = NOW() + INTERVAL '1 minute' * $2 WHERE id = $1"
|
||||
@@ -107,12 +103,7 @@ pub async fn check_and_schedule_reading_status_push(pool: &PgPool) -> Result<()>
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
let interval_minutes: i64 = match push_mode.as_str() {
|
||||
"hourly" => 60,
|
||||
"daily" => 1440,
|
||||
"weekly" => 10080,
|
||||
_ => 1440,
|
||||
};
|
||||
let interval_minutes = mode_to_interval_minutes(&push_mode);
|
||||
|
||||
sqlx::query(
|
||||
"UPDATE libraries SET last_reading_status_push_at = NOW(), next_reading_status_push_at = NOW() + INTERVAL '1 minute' * $2 WHERE id = $1"
|
||||
@@ -176,12 +167,7 @@ pub async fn check_and_schedule_download_detection(pool: &PgPool) -> Result<()>
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
let interval_minutes: i64 = match detection_mode.as_str() {
|
||||
"hourly" => 60,
|
||||
"daily" => 1440,
|
||||
"weekly" => 10080,
|
||||
_ => 1440,
|
||||
};
|
||||
let interval_minutes = mode_to_interval_minutes(&detection_mode);
|
||||
|
||||
sqlx::query(
|
||||
"UPDATE libraries SET last_download_detection_at = NOW(), next_download_detection_at = NOW() + INTERVAL '1 minute' * $2 WHERE id = $1"
|
||||
@@ -238,12 +224,7 @@ pub async fn check_and_schedule_metadata_refreshes(pool: &PgPool) -> Result<()>
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
let interval_minutes = match refresh_mode.as_str() {
|
||||
"hourly" => 60,
|
||||
"daily" => 1440,
|
||||
"weekly" => 10080,
|
||||
_ => 1440,
|
||||
};
|
||||
let interval_minutes = mode_to_interval_minutes(&refresh_mode);
|
||||
|
||||
sqlx::query(
|
||||
"UPDATE libraries SET last_metadata_refresh_at = NOW(), next_metadata_refresh_at = NOW() + INTERVAL '1 minute' * $2 WHERE id = $1"
|
||||
|
||||
@@ -5,23 +5,8 @@ use sha2::{Digest, Sha256};
|
||||
use std::path::Path;
|
||||
use chrono::Utc;
|
||||
|
||||
pub fn remap_libraries_path(path: &str) -> String {
|
||||
if let Ok(root) = std::env::var("LIBRARIES_ROOT_PATH") {
|
||||
if path.starts_with("/libraries/") {
|
||||
return path.replacen("/libraries", &root, 1);
|
||||
}
|
||||
}
|
||||
path.to_string()
|
||||
}
|
||||
|
||||
pub fn unmap_libraries_path(path: &str) -> String {
|
||||
if let Ok(root) = std::env::var("LIBRARIES_ROOT_PATH") {
|
||||
if path.starts_with(&root) {
|
||||
return path.replacen(&root, "/libraries", 1);
|
||||
}
|
||||
}
|
||||
path.to_string()
|
||||
}
|
||||
pub use stripstream_core::paths::remap_libraries_path;
|
||||
pub use stripstream_core::paths::unmap_libraries_path;
|
||||
|
||||
pub fn compute_fingerprint(path: &Path, size: u64, mtime: &DateTime<Utc>) -> Result<String> {
|
||||
// Optimized: only use size + mtime + first bytes of filename for fast fingerprinting
|
||||
|
||||
Reference in New Issue
Block a user