1 parent
f47217d5a3
commit
8ceb3c8be8
60 files changed
+10884
No files matched your search
@@ -0,0 +1,121 @@
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use jm_core::PathMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Daemon configuration. Loaded from TOML plus `JELLYMOVE_*` environment
|
||||
/// variables (nested keys use `__`, e.g. `JELLYMOVE_PEER__TOKEN`).
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Config {
|
||||
/// Name shown in the UI and in job history, e.g. "cloud" or "home".
|
||||
pub node_name: String,
|
||||
#[serde(default = "default_listen")]
|
||||
pub listen: SocketAddr,
|
||||
/// Where the SQLite database lives.
|
||||
#[serde(default = "default_data_dir")]
|
||||
pub data_dir: PathBuf,
|
||||
pub jellyfin: JellyfinConfig,
|
||||
/// Jellyfin path → local path translations. Leave empty when this agent
|
||||
/// mounts media at the same paths as Jellyfin (recommended).
|
||||
#[serde(default)]
|
||||
pub path_map: PathMap,
|
||||
pub peer: Option<PeerConfig>,
|
||||
/// When an item arrives from the peer's library "X", put it in local
|
||||
/// library `incoming_libraries["X"]`. Unlisted libraries map to a local
|
||||
/// library with the same name.
|
||||
#[serde(default)]
|
||||
pub incoming_libraries: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub transfer: TransferConfig,
|
||||
#[serde(default)]
|
||||
pub ui: UiConfig,
|
||||
#[serde(default)]
|
||||
pub hooks: HooksConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct JellyfinConfig {
|
||||
pub url: String,
|
||||
pub api_key: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct PeerConfig {
|
||||
/// Base URL of the other jellymove agent, e.g. `https://cloud.example.com:8097`.
|
||||
pub url: String,
|
||||
/// Shared secret. Both agents must use the same value.
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct TransferConfig {
|
||||
/// Cap on incoming transfer speed in megabits per second. 0 = unlimited.
|
||||
pub bandwidth_limit_mbps: f64,
|
||||
/// Attempts per file before the job fails (each attempt resumes).
|
||||
pub retries: u32,
|
||||
/// How long to wait for Jellyfin to index a moved item.
|
||||
pub scan_timeout_secs: u64,
|
||||
pub max_concurrent_jobs: usize,
|
||||
}
|
||||
|
||||
impl Default for TransferConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bandwidth_limit_mbps: 0.0,
|
||||
retries: 20,
|
||||
scan_timeout_secs: 1200,
|
||||
max_concurrent_jobs: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct UiConfig {
|
||||
/// Protect the web UI with HTTP Basic auth. Strongly recommended if the
|
||||
/// port is reachable from anywhere but localhost.
|
||||
pub username: Option<String>,
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct HooksConfig {
|
||||
/// Shell command run on the destination after a move finishes, e.g.
|
||||
/// `docker restart jellyswarrm` to clear Jellyswarrm's merge cache.
|
||||
/// Gets JELLYMOVE_ITEM_NAME and JELLYMOVE_TARGET_FOLDER in its environment.
|
||||
pub post_move: Option<String>,
|
||||
}
|
||||
|
||||
fn default_listen() -> SocketAddr {
|
||||
"0.0.0.0:8097".parse().expect("valid")
|
||||
}
|
||||
|
||||
fn default_data_dir() -> PathBuf {
|
||||
PathBuf::from("./data")
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn bytes_per_sec(&self) -> Option<std::num::NonZeroU32> {
|
||||
let bps = self.transfer.bandwidth_limit_mbps * 1_000_000.0 / 8.0;
|
||||
if bps >= 1.0 {
|
||||
std::num::NonZeroU32::new(bps.min(u32::MAX as f64) as u32)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Redacted copy safe to show in the UI.
|
||||
pub fn redacted(&self) -> Config {
|
||||
let mut c = self.clone();
|
||||
c.jellyfin.api_key = "••••".into();
|
||||
if let Some(p) = c.peer.as_mut() {
|
||||
p.token = "••••".into();
|
||||
}
|
||||
if c.ui.password.is_some() {
|
||||
c.ui.password = Some("••••".into());
|
||||
}
|
||||
c
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user