diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | base/src/database.rs | 2 | ||||
-rw-r--r-- | client/src/lib.rs | 18 | ||||
-rw-r--r-- | tool/Cargo.toml | 2 | ||||
-rw-r--r-- | tool/src/main.rs | 36 |
5 files changed, 57 insertions, 3 deletions
@@ -1461,6 +1461,7 @@ dependencies = [ "env_logger", "indicatif", "jellybase", + "jellyclient", "jellycommon", "jellymatroska", "jellyremuxer", @@ -1470,6 +1471,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "tokio", ] [[package]] diff --git a/base/src/database.rs b/base/src/database.rs index 74eacb0..f46f0fb 100644 --- a/base/src/database.rs +++ b/base/src/database.rs @@ -9,7 +9,7 @@ use jellycommon::{ Node, }; use log::info; -use std::{collections::HashMap, path::Path}; +use std::path::Path; use typed_sled::Tree; pub use sled; diff --git a/client/src/lib.rs b/client/src/lib.rs index 61365a3..b80f705 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -5,7 +5,7 @@ */ use anyhow::Result; use jellycommon::user::UserPermission; -use log::debug; +use log::{debug, info}; use reqwest::{ header::{HeaderMap, HeaderValue}, Client, @@ -100,7 +100,10 @@ impl Session { debug!("downloading asset {role:?} for {id:?}"); let mut r = self .client - .get(format!("{}/n/{id}/asset?role={role}&width={width}", self.instance.base())) + .get(format!( + "{}/n/{id}/asset?role={role}&width={width}", + self.instance.base() + )) .send() .await?; while let Some(chunk) = r.chunk().await? { @@ -109,6 +112,17 @@ impl Session { Ok(()) } + pub async fn reimport(&self) -> Result<()> { + // TODO error handling + info!("reimport"); + self.client + .post(format!("{}/admin/import", self.instance.base())) + .send() + .await?; + info!("done"); + Ok(()) + } + pub fn stream(&self, id: &str, stream_spec: &StreamSpec) -> String { format!( "{}/n/{}/stream?{}&{}", diff --git a/tool/Cargo.toml b/tool/Cargo.toml index a53e1bd..02738ec 100644 --- a/tool/Cargo.toml +++ b/tool/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] jellycommon = { path = "../common" } jellybase = { path = "../base" } +jellyclient = { path = "../client" } jellymatroska = { path = "../matroska" } jellyremuxer = { path = "../remuxer" } @@ -15,6 +16,7 @@ anyhow = "1.0.75" clap = { version = "4.4.6", features = ["derive"] } reqwest = { version = "0.11.20", features = ["blocking", "json"] } indicatif = "0.17.7" +tokio = { workspace = true } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" diff --git a/tool/src/main.rs b/tool/src/main.rs index 26865c6..47c9a53 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -11,6 +11,7 @@ pub mod migrate; use base64::Engine; use clap::{Parser, Subcommand, ValueEnum}; use import::import; +use jellyclient::{Instance, LoginDetails}; use jellycommon::{config::GlobalConfig, Node, NodeKind, NodePrivate, NodePublic}; use log::{info, warn}; use migrate::migrate; @@ -76,6 +77,16 @@ enum Action { mode: MigrateMode, save_location: PathBuf, }, + Reimport { + /// Path to global jellything config + config: PathBuf, + /// Custom hostname, the config's is used by default + #[arg(long)] + hostname: Option<String>, + /// Disable TLS. Dont use this. + #[arg(long)] + no_tls: bool, + }, } #[derive(Debug, Clone, Copy, PartialEq, ValueEnum)] @@ -147,6 +158,31 @@ fn main() -> anyhow::Result<()> { } a @ Action::New { .. } => import(a, args.dry), a @ Action::Migrate { .. } => migrate(a), + Action::Reimport { + config, + hostname, + no_tls, + } => tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + .block_on(async move { + let config = serde_yaml::from_reader::<_, GlobalConfig>(File::open(config)?)?; + + let inst = Instance::new(hostname.unwrap_or(config.hostname.clone()), !no_tls); + info!("login"); + let session = inst + .login(LoginDetails { + drop_permissions: None, + expire: None, + password: config.admin_password, + username: config.admin_username, + }) + .await?; + + session.reimport().await?; + Ok(()) + }), } } |