From dfdce26961ed87d471d9c2a8d2719fbbe78fb9fb Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 6 Aug 2023 14:27:20 +0200 Subject: delete cache from admin --- server/src/routes/ui/admin/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'server/src/routes/ui/admin') diff --git a/server/src/routes/ui/admin/mod.rs b/server/src/routes/ui/admin/mod.rs index f779700..c6a89ca 100644 --- a/server/src/routes/ui/admin/mod.rs +++ b/server/src/routes/ui/admin/mod.rs @@ -18,6 +18,7 @@ use crate::{ uri, }; use anyhow::anyhow; +use jellybase::CONF; use rand::Rng; use rocket::{form::Form, get, post, FromForm, State}; use std::time::Instant; @@ -52,6 +53,9 @@ pub fn admin_dashboard<'a>( form[method="POST", action=uri!(r_admin_import())] { input[type="submit", value="(Re-)Import Library"]; } + form[method="POST", action=uri!(r_admin_delete_cache())] { + input[type="submit", value="Delete Cache"]; + } h2 { "Invitations" } form[method="POST", action=uri!(r_admin_invite())] { input[type="submit", value="Generate new invite code"]; @@ -146,3 +150,21 @@ pub async fn r_admin_import( ), ) } + +#[post("/admin/delete_cache")] +pub async fn r_admin_delete_cache( + session: AdminSession, + database: &State, +) -> MyResult> { + drop(session); + let t = Instant::now(); + let r = tokio::fs::remove_dir_all(&CONF.cache_path).await; + tokio::fs::create_dir(&CONF.cache_path).await?; + admin_dashboard( + &database, + Some( + r.map_err(|e| e.into()) + .map(|_| format!("Cache deleted; took {:?}", t.elapsed())), + ), + ) +} -- cgit v1.2.3-70-g09d2