Link without creating a Base

This commit is contained in:
Joscha 2023-08-13 21:22:57 +02:00
parent 373b3168f1
commit 98132cc00b
2 changed files with 12 additions and 8 deletions

View file

@ -10,7 +10,7 @@ use time::OffsetDateTime;
use crate::{ use crate::{
config::Config, config::Config,
server::web::{ server::web::{
base::{Base, Tab}, base::Base,
paths::{PathAdminQueueAdd, PathQueue}, paths::{PathAdminQueueAdd, PathQueue},
}, },
somehow, somehow,
@ -43,6 +43,6 @@ pub async fn post_admin_queue_add(
.execute(&db) .execute(&db)
.await?; .await?;
let link = Base::new(config, Tab::None).link(PathQueue {}); let link = Base::link_with_config(config, PathQueue {});
Ok(Redirect::to(&format!("{link}"))) Ok(Redirect::to(&format!("{link}")))
} }

View file

@ -32,25 +32,29 @@ impl Base {
Tab::Queue => "queue", Tab::Queue => "queue",
}; };
Self { Self {
link_logo_svg: Self::link_from_base(&config.web_base, LOGO_SVG), link_logo_svg: Self::link_with_config(config, LOGO_SVG),
link_base_css: Self::link_from_base(&config.web_base, BASE_CSS), link_base_css: Self::link_with_config(config, BASE_CSS),
link_index: Self::link_from_base(&config.web_base, PathIndex {}), link_index: Self::link_with_config(config, PathIndex {}),
link_queue: Self::link_from_base(&config.web_base, PathQueue {}), link_queue: Self::link_with_config(config, PathQueue {}),
web_base: config.web_base.clone(), web_base: config.web_base.clone(),
repo_name: config.repo_name.clone(), repo_name: config.repo_name.clone(),
tab, tab,
} }
} }
fn link_from_base<P: fmt::Display>(base: &str, to: P) -> Link { fn link_with_base<P: fmt::Display>(base: &str, to: P) -> Link {
let to = format!("{to}"); let to = format!("{to}");
assert!(!base.ends_with('/')); assert!(!base.ends_with('/'));
assert!(to.starts_with('/')); assert!(to.starts_with('/'));
Link(format!("{base}{to}")) Link(format!("{base}{to}"))
} }
pub fn link_with_config<P: fmt::Display>(config: &Config, to: P) -> Link {
Self::link_with_base(&config.web_base, to)
}
pub fn link<P: fmt::Display>(&self, to: P) -> Link { pub fn link<P: fmt::Display>(&self, to: P) -> Link {
Self::link_from_base(&self.web_base, to) Self::link_with_base(&self.web_base, to)
} }
} }