yagcdn/backend/src/statics.rs

39 lines
1.4 KiB
Rust
Raw Normal View History

2019-07-27 17:14:08 +02:00
use crate::{config::Opt, service::Github};
use std::{env, time::Duration};
2019-07-27 17:14:08 +02:00
use structopt::StructOpt;
2019-07-24 17:54:00 +02:00
const VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) const REDIRECT_AGE: Duration = Duration::from_secs(5 * 60);
2019-07-27 16:15:11 +02:00
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
2019-07-24 17:54:00 +02:00
lazy_static! {
2019-08-09 19:43:58 +02:00
pub(crate) static ref USER_AGENT: String = format!("yagcdn/{}", VERSION);
2019-07-27 17:14:08 +02:00
pub(crate) static ref OPT: Opt = Opt::from_args();
pub(crate) static ref GITHUB_AUTH_QUERY: String = Github::auth_query().unwrap_or_default();
2019-07-28 14:45:39 +02:00
pub(crate) static ref CF_ZONE_IDENT: String = OPT
.cf_zone
.clone()
2019-07-28 14:54:36 +02:00
.or_else(|| load_env_var("CF_ZONE_IDENT"))
2019-07-28 14:45:39 +02:00
.expect("Cloudflare zone identifier not set");
pub(crate) static ref CF_AUTH_KEY: String = OPT
.cf_auth_key
.clone()
2019-07-28 14:54:36 +02:00
.or_else(|| load_env_var("CF_AUTH_KEY"))
2019-07-28 14:45:39 +02:00
.expect("Cloudflare auth key not set");
pub(crate) static ref CF_AUTH_USER: String = OPT
.cf_auth_user
.clone()
2019-07-28 14:54:36 +02:00
.or_else(|| load_env_var("CF_AUTH_USER"))
2019-07-28 14:45:39 +02:00
.expect("Cloudflare auth user not set");
pub(crate) static ref HOSTNAME: String = OPT
.hostname
.clone()
2019-08-09 19:43:58 +02:00
.or_else(|| load_env_var("YAGCDN_HOSTNAME"))
.unwrap_or_else(|| "yagcdn.tk".to_string());
2019-07-24 17:54:00 +02:00
}
2019-07-28 14:54:36 +02:00
pub(crate) fn load_env_var(key: &str) -> Option<String> {
env::var(key)
.ok()
.and_then(|val| if val.is_empty() { None } else { Some(val) })
}