use crate::{
bridge::library::client::{self as library_client, LibrarySession},
settings::WorkerSettings,
};
use indicatrix_net::library::{LibraryRequest, LibraryResponse};
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
#[must_use]
pub fn mirror_source_id(worker: &WorkerSettings) -> String {
format!("remote-library:{}", worker.address)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MirrorOptions {
pub max_attachment_bytes: u64,
}
impl Default for MirrorOptions {
fn default() -> Self {
Self {
max_attachment_bytes: 50 * 1024 * 1024,
}
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct MirrorCounts {
pub total_found: usize,
pub new_count: usize,
pub updated_count: usize,
pub skipped_unchanged: usize,
pub skipped_deleted: usize,
pub failed: usize,
pub attachments_fetched: usize,
pub attachments_skipped_too_large: usize,
pub attachment_bytes_fetched: u64,
pub local_conflicts_skipped: usize,
pub orphaned_mirror_states: u64,
}
#[derive(Debug, Clone)]
pub struct MirrorProgress {
pub processed: usize,
pub counts: MirrorCounts,
pub current_title: String,
}
#[derive(Debug, Clone)]
pub enum MirrorOutcome {
Completed(MirrorCounts),
Cancelled(MirrorCounts),
Failed(String),
}
pub struct MirrorHandle {
pub(super) cancel: Arc<AtomicBool>,
}
impl MirrorHandle {
pub fn cancel(&self) {
self.cancel.store(true, Ordering::Relaxed);
}
}
pub trait LibraryTransport {
fn request(
&self,
req: &LibraryRequest,
) -> Result<LibraryResponse, library_client::LibraryClientError>;
}
impl LibraryTransport for WorkerSettings {
fn request(
&self,
req: &LibraryRequest,
) -> Result<LibraryResponse, library_client::LibraryClientError> {
library_client::request(self, req)
}
}
impl LibraryTransport for LibrarySession {
fn request(
&self,
req: &LibraryRequest,
) -> Result<LibraryResponse, library_client::LibraryClientError> {
self.request(req)
}
}