1 parent
f47217d5a3
commit
8ceb3c8be8
60 files changed
+10884
No files matched your search
@@ -0,0 +1,132 @@
|
||||
//! Local demo: two jellymove agents ("cloud" on :8097, "home" on :8098), each
|
||||
//! with a fake Jellyfin and some throwaway media in a temp folder.
|
||||
//!
|
||||
//! npm --prefix ui ci && npm --prefix ui run build
|
||||
//! cargo run -p jm-server --example demo
|
||||
//!
|
||||
//! Then open http://127.0.0.1:8097 and move something to "home".
|
||||
|
||||
#[path = "../tests/fake_jellyfin/mod.rs"]
|
||||
#[allow(dead_code)]
|
||||
mod fake_jellyfin;
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use fake_jellyfin::{Fake, Lib};
|
||||
use jm_server::config::{
|
||||
Config, HooksConfig, JellyfinConfig, PeerConfig, TransferConfig, UiConfig,
|
||||
};
|
||||
|
||||
fn write(path: &Path, len: usize) {
|
||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||
let data: Vec<u8> = (0..len as u32)
|
||||
.map(|i| (i.wrapping_mul(2654435761) >> 11) as u8)
|
||||
.collect();
|
||||
std::fs::write(path, data).unwrap();
|
||||
}
|
||||
|
||||
fn libs(root: &Path) -> Vec<Lib> {
|
||||
vec![
|
||||
Lib {
|
||||
name: "Movies".into(),
|
||||
collection_type: "movies",
|
||||
location: root.join("movies"),
|
||||
},
|
||||
Lib {
|
||||
name: "TV Shows".into(),
|
||||
collection_type: "tvshows",
|
||||
location: root.join("tv"),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber_init();
|
||||
let tmp = tempfile::tempdir()?;
|
||||
let cloud = tmp.path().join("cloud");
|
||||
let home = tmp.path().join("home");
|
||||
for r in [&cloud, &home] {
|
||||
std::fs::create_dir_all(r.join("movies"))?;
|
||||
std::fs::create_dir_all(r.join("tv"))?;
|
||||
}
|
||||
const MB: usize = 1024 * 1024;
|
||||
for (folder, size) in [
|
||||
("Arrival (2016)", 180 * MB),
|
||||
("Blade Runner (1982)", 120 * MB),
|
||||
("Heat (1995)", 60 * MB),
|
||||
] {
|
||||
let base = cloud.join("movies").join(folder);
|
||||
write(&base.join(format!("{folder}.mkv")), size);
|
||||
write(&base.join(format!("{folder}.nfo")), 300);
|
||||
write(&base.join(format!("{folder}.en.srt")), 40_000);
|
||||
write(&base.join("poster.jpg"), 200_000);
|
||||
}
|
||||
for ep in 1..=6 {
|
||||
write(
|
||||
&cloud.join(format!("tv/Severance/Season 01/Severance S01E{ep:02}.mkv")),
|
||||
20 * MB,
|
||||
);
|
||||
}
|
||||
write(
|
||||
&home.join("movies/The Thing (1982)/The Thing (1982).mkv"),
|
||||
40 * MB,
|
||||
);
|
||||
|
||||
let fake_cloud = Fake::new(libs(&cloud));
|
||||
let fake_home = Fake::new(libs(&home));
|
||||
if let Some(id) = fake_cloud.find("Movie", "Arrival") {
|
||||
fake_cloud.set_user_data(&id, serde_json::json!({"Played": true, "PlayCount": 1}));
|
||||
}
|
||||
let jf_cloud = fake_cloud.serve().await;
|
||||
let jf_home = fake_home.serve().await;
|
||||
|
||||
let mut tasks = Vec::new();
|
||||
for (name, root, jf, port, peer_port) in [
|
||||
("cloud", &cloud, jf_cloud, 8097, 8098),
|
||||
("home", &home, jf_home, 8098, 8097),
|
||||
] {
|
||||
let cfg = Config {
|
||||
node_name: name.into(),
|
||||
listen: format!("127.0.0.1:{port}").parse()?,
|
||||
data_dir: root.join(".state"),
|
||||
jellyfin: JellyfinConfig {
|
||||
url: jf,
|
||||
api_key: "demo".into(),
|
||||
},
|
||||
path_map: Default::default(),
|
||||
peer: Some(PeerConfig {
|
||||
url: format!("http://127.0.0.1:{peer_port}"),
|
||||
token: "demo-token".into(),
|
||||
}),
|
||||
incoming_libraries: Default::default(),
|
||||
// Throttled so you can watch the progress bar.
|
||||
transfer: TransferConfig {
|
||||
bandwidth_limit_mbps: 200.0,
|
||||
..Default::default()
|
||||
},
|
||||
ui: UiConfig::default(),
|
||||
hooks: HooksConfig::default(),
|
||||
};
|
||||
std::fs::create_dir_all(&cfg.data_dir)?;
|
||||
let store = jm_store::Store::open(&cfg.data_dir.join("db"))?;
|
||||
let state = Arc::new(jm_server::state::AppState::new(cfg, store)?);
|
||||
jm_server::runner::resume_all(&state).await?;
|
||||
let listener = tokio::net::TcpListener::bind(("127.0.0.1", port)).await?;
|
||||
tasks.push(tokio::spawn(async move {
|
||||
axum::serve(listener, jm_server::api::router(state)).await
|
||||
}));
|
||||
}
|
||||
println!("demo media in {}", tmp.path().display());
|
||||
println!("cloud: http://127.0.0.1:8097 home: http://127.0.0.1:8098 (Ctrl+C to stop)");
|
||||
tokio::signal::ctrl_c().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn tracing_subscriber_init() {
|
||||
// Keep the demo quiet unless asked.
|
||||
if std::env::var_os("RUST_LOG").is_some() {
|
||||
eprintln!("(set up your own subscriber for logs)");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user