list custom_domains

thanks a lot to @fdb-hiroshima and @BaptisteGelez for helping with the
code.
This commit is contained in:
Igor Galić 2019-05-25 23:35:00 +02:00 committed by Igor Galić
parent 65ae51b7e5
commit 351c01f71c
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
2 changed files with 13 additions and 1 deletions

View File

@ -81,7 +81,7 @@ pub struct NewBlog {
pub summary_html: SafeString, pub summary_html: SafeString,
pub icon_id: Option<i32>, pub icon_id: Option<i32>,
pub banner_id: Option<i32>, pub banner_id: Option<i32>,
pub custom_domain: Option<String>, pub custom_domain: Option<Host>,
} }
const BLOG_PREFIX: &str = "~"; const BLOG_PREFIX: &str = "~";
@ -311,6 +311,15 @@ impl Blog {
.map(|_| ()) .map(|_| ())
.map_err(Error::from) .map_err(Error::from)
} }
pub fn list_custom_domains(conn: &Connection) -> Result<Vec<String>> {
blogs::table
.filter(blogs::custom_domain.is_not_null())
.select(blogs::custom_domain)
.load::<Option<String>>(conn)
.map_err(Error::from)
.map(|res| res.into_iter().map(|s| s.unwrap()).collect::<Vec<_>>())
}
} }
impl<'a, 'r> FromRequest<'a, 'r> for Host { impl<'a, 'r> FromRequest<'a, 'r> for Host {

View File

@ -175,6 +175,9 @@ Then try to restart Plume
println!("Please refer to the documentation to see how to configure it."); println!("Please refer to the documentation to see how to configure it.");
} }
let custom_domains = plume_models::blogs::Blog::list_custom_domains(&dbpool.get().unwrap()).unwrap();
dbg!(custom_domains);
let rocket = rocket::custom(CONFIG.rocket.clone().unwrap()) let rocket = rocket::custom(CONFIG.rocket.clone().unwrap())
.mount( .mount(
"/", "/",