diff --git a/build.rs b/build.rs index b044c29..6979e0f 100644 --- a/build.rs +++ b/build.rs @@ -1,20 +1,13 @@ use anyhow::{ensure, Result}; use std::fs::File; -use std::io::{self, Write}; +use std::io; use std::path::{Path, PathBuf}; use std::process::Command; use zip::ZipWriter; -fn main() { +fn main() -> Result<()> { let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); - let mut rs_file = File::create(out_dir.join("zip.rs")).unwrap(); - match attempt(&out_dir) { - Ok(()) => writeln!(rs_file, r#"Some(include_bytes!("source.zip"))"#).unwrap(), - Err(_) => writeln!(rs_file, "None").unwrap(), - } -} -fn attempt(out_dir: &Path) -> Result<()> { let output = Command::new("cargo") .args(["package", "--list", "--allow-dirty"]) .output()?; diff --git a/src/app.rs b/src/app.rs index f3fa227..6b78fa3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -144,16 +144,17 @@ struct Code { } #[get("/code")] -fn code() -> Option { - let zip = include!(concat!(env!("OUT_DIR"), "/zip.rs"))?; - Some(Code { +fn code() -> Code { + let zip = include_bytes!(concat!(env!("OUT_DIR"), "/source.zip")); + + Code { zip, content_type: ContentType::ZIP, disposition: Header::new( "content-disposition", r#"attachment; filename="emojos.in.zip""#, ), - }) + } } #[get("/static/site.css")]