diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-28 20:25:43 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-28 20:25:43 +0100 |
commit | 1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68 (patch) | |
tree | 8dcbe5947585d032480324c2867cc6cec247fbee | |
parent | f3d1ce1360d8829b987dd3403e821cebcff58d95 (diff) | |
download | jellything-1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68.tar jellything-1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68.tar.bz2 jellything-1b8181e34fbbc6a6dfb89afa704e1e1d8fe7ff68.tar.zst |
show current import avaiil
-rw-r--r-- | import/src/lib.rs | 8 | ||||
-rw-r--r-- | server/src/routes/ui/admin/mod.rs | 7 | ||||
-rw-r--r-- | web/style/layout.css | 4 |
3 files changed, 16 insertions, 3 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index 97b9950..9618d96 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -39,9 +39,10 @@ use std::{ ops::Deref, path::{Path, PathBuf}, sync::{Arc, LazyLock}, + time::Duration, }; use tmdb::{parse_release_date, Tmdb}; -use tokio::{io::AsyncWriteExt, sync::Semaphore, task::spawn_blocking}; +use tokio::{io::AsyncWriteExt, sync::Semaphore, task::spawn_blocking, time::sleep}; use trakt::Trakt; static IMPORT_SEM: LazyLock<Semaphore> = LazyLock::new(|| Semaphore::new(1)); @@ -51,9 +52,14 @@ struct Apis { tmdb: Option<Tmdb>, } +pub fn is_importing() -> bool { + IMPORT_SEM.available_permits() <= 0 +} + pub async fn import(db: &DataAcid, fed: &Federation) -> anyhow::Result<()> { let permit = IMPORT_SEM.try_acquire()?; + sleep(Duration::from_secs(5)).await; { let txn = db.inner.begin_write()?; let mut table = txn.open_table(T_NODE_IMPORT)?; diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index c34a93a..0508c7d 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -22,7 +22,7 @@ use jellybase::{ federation::Federation, CONF, }; -use jellyimport::import; +use jellyimport::{import, is_importing}; use rand::Rng; use rocket::{form::Form, get, post, FromForm, State}; use std::time::Instant; @@ -65,8 +65,11 @@ pub fn admin_dashboard<'a>( li{a[href=uri!(r_admin_log(false))] { "Server Log (Full) " }} } h2 { "Library" } + @if is_importing() { + section.message { p.warn { "An import is currently running." } } + } form[method="POST", action=uri!(r_admin_import())] { - input[type="submit", value="(Re-)Import Library"]; + input[type="submit", disabled=is_importing(), value="(Re-)Import Library"]; } form[method="POST", action=uri!(r_admin_delete_cache())] { input[type="submit", value="Delete Cache"]; diff --git a/web/style/layout.css b/web/style/layout.css index e7bf91e..8054c92 100644 --- a/web/style/layout.css +++ b/web/style/layout.css @@ -78,6 +78,10 @@ section.message { color: var(--c-error); font-family: monospace; } +.warn { + padding: 1em; + color: var(--c-warn); +} .success { padding: 1em; color: var(--c-success); |