Skip to content

Commit

Permalink
Clean prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-zip committed Oct 8, 2023
1 parent af63fbe commit e134868
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 62 deletions.
7 changes: 0 additions & 7 deletions maid_reports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,4 @@ name = "maid_reports"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
parking_lot = "0.12.1"
serde = "1.0.188"
serde_json = "1.0.107"
tokio = "1.32.0"
warp = "0.3.6"
18 changes: 0 additions & 18 deletions maid_reports/src/api/api.rs
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
use crate::meow::meow::*;
use std::fs::File;

pub fn read_file(path: String) -> String {

match File::open(file_path) {
Ok(file) => {
use std::io::Read;
let mut reader = std::io::BufReader::new(file);
let mut content = String::new();
reader
.read_to_string(&mut content)
.expect("Failed to read file");
content
}
Err(_) => String::from("Error reading the JSONL file"),
}
}
40 changes: 3 additions & 37 deletions maid_reports/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
mod api;
mod meow;

use crate::api::api::*;
use warp::Filter;

#[tokio::main]
async fn main() {
// Define a filter that matches a GET request to the /jsonl endpoint.
// Replace "your_jsonl_file.jsonl" with the path to your JSONL file.
let config = read_meow("/var/maid/maid_lists/embedded/config.meow", false);
let file_path = format!("{}{}", config["REPORT_BASE_PATH"], config["REPORT_LOG"]);

let jsonl_route = warp::path!("jsonl").and(warp::get()).map(|| {
// Read the JSONL file and return it as a response.
let file_content = read_file(file_path);
warp::reply::with_header(
file_content,
warp::http::header::CONTENT_TYPE,
"application/json",
)
});


let index_page = config["INDEX"].to_string();
let index = warp::path!("/").and(warp::get()).map(|| {
let file_content = read_file(index_page);
warp::reply::with_header(
file_content,
warp::http::header::CONTENT_TYPE,
"text/html",
)
});

// Start the Warp server.
warp::serve(jsonl_route, index).run(([127, 0, 0, 1], 8000)).await;
}
fn main() {
println!("A");
}

0 comments on commit e134868

Please sign in to comment.