config issues are being ignored for now there are bigger things to deal with

This commit is contained in:
shockrah 2020-01-29 23:25:37 -08:00
parent e0ede8d96b
commit a3519e32a6
2 changed files with 2 additions and 44 deletions

View File

@ -6,6 +6,7 @@
extern crate rocket_contrib;
use dotenv;
use rocket_contrib::serve::StaticFiles;
use rocket_contrib::templates::Template;

View File

@ -2,54 +2,23 @@
// All new servers come with this as a default so that
use rocket_contrib::templates::Template;
use rocket::response::NamedFile;
use dotenv;
use std::env;
use std::path::Path;
use std::fs::read_to_string;
use serde_derive::Deserialize;
// Purely for backend purposes
#[derive(Serialize, Deserialize, Debug)]
pub struct WebsiteConfig {
url: Option<String>, // default is freechat.io - clean url of domain
favicon: Option<String>, // uri path to the favicon i.e. /media/static/favicon.png
motto: Option<String>,
title: Option<String>,
description: Option<String>,
og_type: Option<String>,
stylesheet: String,
}
pub fn init() {
// Default values which are later overriden
env::set_var("web_url", "freechat.io");
env::set_var("web_favicon", "/static/images/favicon.png");
env::set_var("web_motto", "Decentralized free chat platform");
env::set_var("web_title", "Freechat");
env::set_var("web_og_type", "Decentralized Chat Platform");
// If there's a problem we're going to panic and that's fine to be completely honest
if let Ok(file) = read_to_string("configs/website.toml") {
let config: WebsiteConfig = toml::from_str(&file).unwrap();
println!("file contents: {:?}", config);
env::set_var("web_url", config.url.unwrap());
env::set_var("web_favicon", config.favicon.unwrap());
env::set_var("web_motto", config.motto.unwrap());
env::set_var("web_title", config.title.unwrap());
env::set_var("web_og_type", config.og_type.unwrap());
}
}
#[get("/")]
pub fn homepage() -> Template {
// look away
Template::render("index", WebsiteConfig {
url: Some(env::var("web_url").unwrap()),
favicon: Some(env::var("web_favicon").unwrap()),
motto: Some(env::var("web_motto").unwrap()),
title: Some(env::var("web_title").unwrap()),
description: Some(env::var("web_description").unwrap()),
og_type: Some(env::var("web_og_type").unwrap()),
stylesheet: "/static/css/index.css".to_string()
})
}
@ -57,12 +26,6 @@ pub fn homepage() -> Template {
#[get("/about")]
pub fn about_page() -> Template {
Template::render("about", WebsiteConfig {
url: Some(env::var("web_url").unwrap()),
favicon: Some(env::var("web_favicon").unwrap()),
motto: Some(env::var("web_motto").unwrap()),
title: Some(env::var("web_title").unwrap()),
description: Some(env::var("web_description").unwrap()),
og_type: Some(env::var("web_og_type").unwrap()),
stylesheet: "/static/css/about.css".to_string()
})
}
@ -70,12 +33,6 @@ pub fn about_page() -> Template {
#[get("/servers")]
pub fn server_info() -> Template {
Template::render("servers", WebsiteConfig {
url: Some(env::var("web_url").unwrap()),
favicon: Some(env::var("web_favicon").unwrap()),
motto: Some(env::var("web_motto").unwrap()),
title: Some(env::var("web_title").unwrap()),
description: Some(env::var("web_description").unwrap()),
og_type: Some(env::var("web_og_type").unwrap()),
stylesheet: "/static/css/about.css".to_string()
})
}