texc_web/
lib.rs

1//! TexCreate Web Library <br>
2//! This library is intended to serve a local web server of texcreate-web <br>
3//! Developer: Mustafif Khan <br>
4//! Project: TexCreate  <br>
5//! License: MIT & GPLv2 <br>
6
7
8/// The html raw string for the homepage
9pub mod index;
10/// Contains the creation of zipping files and processing the post request
11pub mod web;
12
13pub use index::INDEX;
14use rocket::fs::NamedFile;
15use rocket::{get, routes};
16use rocket::{Build, Rocket};
17use std::fs::File;
18use std::io::Write;
19use tempdir::TempDir;
20pub use web::*;
21
22
23/// Serves as the home page get request
24#[get("/")]
25pub async fn texc_home() -> Option<NamedFile> {
26    let temp_dir = TempDir::new("html_temp").unwrap();
27    let path = temp_dir.into_path().join("texcreate.html");
28
29    let mut file = File::create(&path).unwrap();
30    file.write_all(INDEX.as_bytes()).unwrap();
31
32    NamedFile::open(&path.as_path()).await.ok()
33}
34
35/// Creates the web server, launch using `texweb().launch()`
36pub fn texweb() -> Rocket<Build> {
37    rocket::build().mount("/", routes![texc_home, texc_post])
38}