diff --git a/.env b/.env new file mode 100644 index 000000000..994287ffe --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +INDEX_CURSEFORGE=false +DEBUG=true \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5f370b3ed..96948e276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,17 @@ edition = "2018" [dependencies] actix-web = "2.0" actix-rt = "1.1.1" +actix-files = "0.2.1" handlebars = { version = "3.0.0", features = ["dir_source"] } serde_json = "1.0" serde = {version="1.0", features=["derive"]} meilisearch-sdk = "0.1.3" -actix-files = "0.2.1" human_format = "1.0.3" reqwest = "0.10.4" log = "0.4.8" env_logger = "0.7.1" mongodb = "1.0.0" bson = "1.0.0" -futures = "0.3.5" \ No newline at end of file +futures = "0.3.5" +dotenv = "0.15" +pulldown-cmark = "0.7.1" \ No newline at end of file diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs index bd00ba6b7..54a3fc8a5 100644 --- a/src/helpers/mod.rs +++ b/src/helpers/mod.rs @@ -1,5 +1,8 @@ mod contains; mod format_human; +use handlebars::*; -pub use contains::ContainsHelper; -pub use format_human::HumanFormatHelper; +pub fn register_helpers(handlebars: &mut Handlebars) { + handlebars.register_helper("contains", Box::new(contains::ContainsHelper)); + handlebars.register_helper("format", Box::new(format_human::HumanFormatHelper)); +} diff --git a/src/main.rs b/src/main.rs index 284c4b9a8..0ea07f3ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use actix_web::{web, App, HttpServer}; use handlebars::*; use actix_web::middleware::Logger; use env_logger::Env; +use std::env; mod database; mod helpers; @@ -20,12 +21,12 @@ mod routes; #[actix_rt::main] async fn main() -> std::io::Result<()> { env_logger::from_env(Env::default().default_filter_or("info")).init(); + dotenv::dotenv().ok(); //Handlebars let mut handlebars = Handlebars::new(); - handlebars.register_helper("contains", Box::new(helpers::ContainsHelper)); - handlebars.register_helper("format", Box::new(helpers::HumanFormatHelper)); + helpers::register_helpers(&mut handlebars); handlebars .register_templates_directory(".hbs", "./templates") .unwrap(); @@ -36,6 +37,7 @@ async fn main() -> std::io::Result<()> { routes::index_mods(client).await.unwrap(); info!("Starting Actix HTTP server!"); + //Init App HttpServer::new(move || { App::new() diff --git a/src/routes/search.rs b/src/routes/search.rs index b2c997313..ea05515b1 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -174,8 +174,8 @@ TODO This method needs a lot of refactoring. Here's a list of changes that need pub async fn index_mods(client: mongodb::Client) -> Result<(), Box>{ let mut docs_to_add: Vec = vec![]; - /*docs_to_add.append(&mut index_database(client).await?); - docs_to_add.append(&mut index_curseforge().await?);*/ + docs_to_add.append(&mut index_database(client).await?); + //docs_to_add.append(&mut index_curseforge(1, 400000).await?); //Write Indexes //Relevance Index @@ -266,20 +266,23 @@ async fn index_database(client: mongodb::Client) -> Result, Box< Ok(docs_to_add) } -async fn index_curseforge() -> Result, Box>{ +async fn index_curseforge(start_index: i32, end_index: i32) -> Result, Box>{ info!("Indexing curseforge mods!"); let mut docs_to_add: Vec = vec![]; let res = reqwest::Client::new().post("https://addons-ecs.forgesvc.net/api/v2/addon") .header(reqwest::header::CONTENT_TYPE, "application/json") - .body(format!("{:?}", (1..400000).collect::>())) + .body(format!("{:?}", (start_index..end_index).collect::>())) .send().await?; let text = &res.text().await?; let curseforge_mods : Vec = serde_json::from_str(text)?; + let mut max_index = 0; + for curseforge_mod in curseforge_mods { + max_index = curseforge_mod.id; if curseforge_mod.game_slug != "minecraft" || !curseforge_mod.website_url.contains("/mc-mods/") { continue; } let mut mod_game_versions = vec![]; @@ -397,6 +400,7 @@ async fn index_curseforge() -> Result, Box>{ }) } + //TODO Reindex every hour for new mods. Ok(docs_to_add) } diff --git a/static/css/create-mod.css b/static/css/create-mod.css index 6ff39ab63..4a3c5bdb4 100644 --- a/static/css/create-mod.css +++ b/static/css/create-mod.css @@ -16,7 +16,7 @@ progress::-moz-progress-bar { background: #0b75d8; } border: none; height: 20px; - background: #999; + background: white; color: #0b75d8; margin: 10px 0 0 0; @@ -40,9 +40,69 @@ progress::-moz-progress-bar { background: #0b75d8; } .creation-parts { margin-top: 30px; - background: #fff; } .creation-part { padding: 5px; +} + +.base-info label { + margin-top: 10px; + display: flex; + flex-direction: column; +} + +.info-display { + display: flex; + flex-direction: row; +} + +.info-display-inputs { + margin: 10px 20px; + width: 100%; + display: flex; + flex-direction: column; +} + +.info-body { + margin-top: 20px; +} + +.info-body textarea { + width: 100%; + height: 500px; + resize: vertical; +} + +.button-container { + display: flex; + flex-direction: row; + justify-content: flex-end; + margin-top: 10px; +} + +.next-button { + font-weight: bold; + color: white; + background-color: #69E781; + border-radius: 5px; + padding: 10px; +} + +.draft-button { + margin-right: 10px; + font-weight: bold; + color: wheat; + background-color: #e1a15a; + border-radius: 5px; + padding: 10px; +} + +.discard-button { + margin-right: 10px; + font-weight: bold; + color: white; + background-color: red; + border-radius: 5px; + padding: 10px; } \ No newline at end of file diff --git a/static/js/main.js b/static/js/main.js index 909e14587..4fcb33f89 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1,3 +1,5 @@ -if (localStorage.getItem("theme")) { - document.documentElement.setAttribute("data-theme", localStorage.getItem("theme")); +window.onload = function () { + if (localStorage.getItem("theme")) { + document.documentElement.setAttribute("theme", localStorage.getItem("theme")); + } } \ No newline at end of file diff --git a/templates/mod-create.hbs b/templates/mod-create.hbs index 4829c8b78..d5242f820 100644 --- a/templates/mod-create.hbs +++ b/templates/mod-create.hbs @@ -5,8 +5,6 @@ - - @@ -17,7 +15,7 @@