add opengraph metadata for preview cards
This commit is contained in:
parent
b0a2f7ec7c
commit
16e7ea4806
7 changed files with 44 additions and 5 deletions
20
src/main.rs
20
src/main.rs
|
@ -30,6 +30,7 @@ struct AppState {
|
|||
}
|
||||
|
||||
struct Config {
|
||||
base_url: String,
|
||||
max_upload_size: u64,
|
||||
max_lifetime: u16,
|
||||
upload_password: String,
|
||||
|
@ -58,12 +59,14 @@ pub fn log_auth_failure(ip_addr: &str) {
|
|||
#[template(path = "index.html")]
|
||||
struct IndexPage {
|
||||
cachebuster: String,
|
||||
base_url: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index(data: web::Data<AppState>) -> impl Responder {
|
||||
IndexPage {
|
||||
cachebuster: data.config.cachebuster.clone(),
|
||||
base_url: data.config.base_url.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +81,7 @@ struct DownloadRequest {
|
|||
struct DownloadPage<'a> {
|
||||
info: DownloadInfo,
|
||||
cachebuster: &'a str,
|
||||
base_url: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -134,6 +138,7 @@ async fn handle_download(
|
|||
offsets,
|
||||
},
|
||||
cachebuster: &data.config.cachebuster,
|
||||
base_url: &data.config.base_url,
|
||||
}
|
||||
.to_response())
|
||||
}
|
||||
|
@ -175,6 +180,7 @@ async fn download_info(
|
|||
#[template(path = "404.html")]
|
||||
struct NotFoundPage<'a> {
|
||||
cachebuster: &'a str,
|
||||
base_url: &'a str,
|
||||
}
|
||||
|
||||
fn not_found<T>(req: HttpRequest, data: web::Data<AppState>, report: bool) -> actix_web::Result<T> {
|
||||
|
@ -184,6 +190,7 @@ fn not_found<T>(req: HttpRequest, data: web::Data<AppState>, report: bool) -> ac
|
|||
}
|
||||
let mut resp = NotFoundPage {
|
||||
cachebuster: &data.config.cachebuster,
|
||||
base_url: &data.config.base_url,
|
||||
}
|
||||
.to_response();
|
||||
*resp.status_mut() = StatusCode::NOT_FOUND;
|
||||
|
@ -269,6 +276,14 @@ where
|
|||
.unwrap_or_else(default)
|
||||
}
|
||||
|
||||
fn env_or_panic<T: FromStr>(var: &str) -> T
|
||||
where
|
||||
<T as FromStr>::Err: Debug,
|
||||
{
|
||||
let val = std::env::var(var).unwrap_or_else(|_| panic!("{} must be set!", var));
|
||||
val.parse::<T>().unwrap_or_else(|_| panic!("Invalid value {} for variable {}", val, var))
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
|
@ -276,6 +291,7 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
let static_dir: PathBuf = env_or_else("TRANSBEAM_STATIC_DIR", || PathBuf::from("static"));
|
||||
let storage_dir: PathBuf = env_or_else("TRANSBEAM_STORAGE_DIR", || PathBuf::from("storage"));
|
||||
let base_url: String = env_or_panic("TRANSBEAM_BASE_URL");
|
||||
let port: u16 = env_or("TRANSBEAM_PORT", 8080);
|
||||
let mnemonic_codes: bool = env_or("TRANSBEAM_MNEMONIC_CODES", true);
|
||||
let reverse_proxy: bool = env_or("TRANSBEAM_REVERSE_PROXY", true);
|
||||
|
@ -284,13 +300,13 @@ async fn main() -> std::io::Result<()> {
|
|||
env_or::<ByteSize>("TRANSBEAM_MAX_UPLOAD_SIZE", ByteSize(16 * bytesize::GB)).as_u64();
|
||||
let max_storage_size: u64 =
|
||||
env_or::<ByteSize>("TRANSBEAM_MAX_STORAGE_SIZE", ByteSize(64 * bytesize::GB)).as_u64();
|
||||
let upload_password: String =
|
||||
std::env::var("TRANSBEAM_UPLOAD_PASSWORD").expect("TRANSBEAM_UPLOAD_PASSWORD must be set!");
|
||||
let upload_password: String = env_or_panic("TRANSBEAM_UPLOAD_PASSWORD");
|
||||
let cachebuster: String = env_or_else("TRANSBEAM_CACHEBUSTER", String::new);
|
||||
|
||||
let data = web::Data::new(AppState {
|
||||
file_store: RwLock::new(FileStore::load(storage_dir.clone(), max_storage_size).await?),
|
||||
config: Config {
|
||||
base_url,
|
||||
max_upload_size,
|
||||
max_lifetime,
|
||||
upload_password,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue