support for configs now there but requries docs

This commit is contained in:
shockrah 2020-01-04 18:15:37 -08:00
parent c4b1b20187
commit 5f281e587b
2 changed files with 31 additions and 13 deletions

View File

@ -1,3 +1,7 @@
url="freechat.io"
favicon="/static/media/favicon.png"
motto="Freely chat with freechat!"
# NOTE: discord/slack/linked(especially) love caching things so make sure you
# write something that yo're proud of the first time lest u doom yourself to have the
# wrong things cahced for a few months
@ -5,15 +9,11 @@
# Used to help sites embed some information about your site
# Especially when the server's site is linked in another freechat/slack/discord server
[open-graph]
[opengraph]
title="Freechat"
type="Decentralized chat"
# again this has a prefix because `type` is a keyword in rust so just yea
og_type="Decentralized chat"
url="freechat.io"
description="Free and open chat platform"
image="/static/media/logo.png"
[general]
url="freechat.io"
favicon:"/static/media/favicon.png"
quip:"Freely chat with freechat!"

View File

@ -3,7 +3,7 @@
use rocket_contrib::templates::Template;
use rocket::response::NamedFile;
use std::path::Path;
use std::fs::File;
use std::fs::read_to_string;
use serde_derive::Deserialize;
// Purely for backend purposes
@ -60,18 +60,36 @@ pub fn init() {
image="/static/media/logo.png"
"#;
if let Ok(mut cfg_file) = File::open(default_path) {
// here we take the file and parse it as toml
// TODO: when we read from the file we should elegantly say there are errors in the config
// instead of going through the basic panic
if let Ok(file) = read_to_string(default_path) {
// This is the only time we should ever write to CTX thus the unsafe is mostly fine
let config: WebsiteConfig = toml::from_str(&file).unwrap();
println!("file contents: {:?}", config);
unsafe {
println!("config found ok{:?}", &CTX);
CTX.url = config.url;
CTX.favicon = config.favicon;
CTX.motto = config.motto;
if let Some(og) = config.opengraph {
CTX.opengraph = Some(OpenGraph {
title: config.opengraph.title,
config.opengraph_type: config.opengraph.config.opengraph_type,
url: config.opengraph.url,
description: config.opengraph.description,
image: config.opengraph.image,
});
}
}
}
else {
// No check because default_config is hardcoded into place
let config: WebsiteConfig = toml::from_str(default_config).unwrap();
unsafe {
CTX.url = config.url;
CTX.favicon = config.favicon;
CTX.motto = config.motto;
}
}
}