|
|
|
@ -4,6 +4,7 @@ extern crate monolith;
|
|
|
|
|
extern crate reqwest;
|
|
|
|
|
|
|
|
|
|
mod args;
|
|
|
|
|
mod macros;
|
|
|
|
|
|
|
|
|
|
use args::AppArgs;
|
|
|
|
|
use monolith::html::{html_to_dom, stringify_document, walk_and_embed_assets};
|
|
|
|
@ -11,11 +12,39 @@ use monolith::http::retrieve_asset;
|
|
|
|
|
use monolith::utils::is_valid_url;
|
|
|
|
|
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::fs::{remove_file, File};
|
|
|
|
|
use std::io::{Error, Write};
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
fn create_file(file_path: &String, content: String) -> Result<(), Error> {
|
|
|
|
|
let file = File::create(file_path.as_str());
|
|
|
|
|
|
|
|
|
|
let mut file = match file {
|
|
|
|
|
Ok(file) => file,
|
|
|
|
|
Err(error) => return Err(error),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if content != str!() {
|
|
|
|
|
file.write_all(content.as_bytes())?;
|
|
|
|
|
file.write_all("\n".as_bytes())?;
|
|
|
|
|
file.sync_all()?;
|
|
|
|
|
} else {
|
|
|
|
|
// Remove the file right away if it had no content
|
|
|
|
|
remove_file(file_path.as_str())?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let app_args = AppArgs::get();
|
|
|
|
|
let cache = &mut HashMap::new();
|
|
|
|
|
|
|
|
|
|
// Attempt to create output file
|
|
|
|
|
if app_args.output != str!() {
|
|
|
|
|
create_file(&app_args.output, str!()).unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if is_valid_url(app_args.url_target.as_str()) {
|
|
|
|
|
// Initialize client
|
|
|
|
|
let mut header_map = HeaderMap::new();
|
|
|
|
@ -33,6 +62,7 @@ fn main() {
|
|
|
|
|
.build()
|
|
|
|
|
.expect("Failed to initialize HTTP client");
|
|
|
|
|
|
|
|
|
|
// Retrieve root document
|
|
|
|
|
let (data, final_url) = retrieve_asset(
|
|
|
|
|
cache,
|
|
|
|
|
&client,
|
|
|
|
@ -65,6 +95,10 @@ fn main() {
|
|
|
|
|
app_args.isolate,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
println!("{}", html);
|
|
|
|
|
if app_args.output == str!() {
|
|
|
|
|
println!("{}", html);
|
|
|
|
|
} else {
|
|
|
|
|
create_file(&app_args.output, html).unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|