diff --git a/Cargo.lock b/Cargo.lock index 3415466..10451e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,9 +92,11 @@ dependencies = [ name = "auracite" version = "0.1.0" dependencies = [ + "ahash", "clap", "clap_derive", "downloader", + "getrandom", "minijinja", "regex", "scraper", @@ -523,8 +525,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ffc8ec4..6276632 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2021" description = "Export your FFXIV character in portable, generic formats" +[lib] +crate-type = ["cdylib", "rlib"] + [dependencies] # Used to scrape the Lodestone HTML pages scraper = "0.20" @@ -19,13 +22,20 @@ regex = "1.11" clap = { version = "4.5", features = ["derive"] } clap_derive = "4.5" -# Download HTML pages, images, etc -downloader = "0.2" - # Used to generate the HTML page to easily preview your exported data minijinja = "2.0" # Used to communicate with the Dalamud plugin # Needs my fork for allowing server shutdown # TODO: upstream this or poke upstream to add this -touche = { git = "https://github.com/redstrate/touche" } \ No newline at end of file +touche = { git = "https://github.com/redstrate/touche" } + +# Not used directly by us, but to disable the "std" feature and is used by the scraper crate. +ahash = { version = "0.8.0", default-features = false } + +# Ditto, but used by the ahash crate. +getrandom = { version = "0.2", features = ["js"] } + +[target.'cfg(not(target_family = "wasm"))'.dependencies] +# Download HTML pages, images, etc +downloader = "0.2" \ No newline at end of file diff --git a/src/downloader.rs b/src/downloader.rs index 6a6fb22..36aa6e5 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -1,25 +1,35 @@ +#[cfg(not(target_family = "wasm"))] use downloader::{Download, Downloader}; use std::path::Path; pub fn download(url: &str, path: &Path) -> Result<(), ()> { - let mut downloader = Downloader::builder().build().unwrap(); - - let mut dl = Download::new(url); - dl = dl.file_name(path); - - if !path.exists() { - let result = downloader.download(&[dl]).unwrap(); - - for r in result { - return match r { - Err(e) => { - println!("Error: {}", e.to_string()); - Err(()) - } - Ok(s) => Ok(()), - }; - } + #[cfg(target_family = "wasm")] + { + // TODO: Implement + Ok(()) } + + #[cfg(not(target_family = "wasm"))] + { + let mut downloader = Downloader::builder().build().unwrap(); - Ok(()) + let mut dl = Download::new(url); + dl = dl.file_name(path); + + if !path.exists() { + let result = downloader.download(&[dl]).unwrap(); + + for r in result { + return match r { + Err(e) => { + println!("Error: {}", e.to_string()); + Err(()) + } + Ok(s) => Ok(()), + }; + } + } + + Ok(()) + } } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8f00a4e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ +pub mod data; +pub mod downloader; +pub mod html; +pub mod parser; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bfcec0e..6b11464 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,6 @@ -mod data; -mod downloader; -mod html; -mod parser; - -use crate::downloader::download; -use crate::html::write_html; -use crate::parser::{parse_lodestone, parse_search}; +use auracite::downloader::download; +use auracite::html::write_html; +use auracite::parser::{parse_lodestone, parse_search}; use clap::Parser; use serde::Deserialize; use std::convert::Infallible;