Base creation page

This commit is contained in:
Jai A
2020-06-22 21:04:17 -07:00
parent 1f4985c7dd
commit 23503dc439
10 changed files with 123 additions and 22 deletions

View File

@@ -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));
}

View File

@@ -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()

View File

@@ -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<dyn Error>>{
let mut docs_to_add: Vec<SearchMod> = 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<Vec<SearchMod>, Box<
Ok(docs_to_add)
}
async fn index_curseforge() -> Result<Vec<SearchMod>, Box<dyn Error>>{
async fn index_curseforge(start_index: i32, end_index: i32) -> Result<Vec<SearchMod>, Box<dyn Error>>{
info!("Indexing curseforge mods!");
let mut docs_to_add: Vec<SearchMod> = 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::<Vec<_>>()))
.body(format!("{:?}", (start_index..end_index).collect::<Vec<_>>()))
.send().await?;
let text = &res.text().await?;
let curseforge_mods : Vec<CurseForgeMod> = 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<Vec<SearchMod>, Box<dyn Error>>{
})
}
//TODO Reindex every hour for new mods.
Ok(docs_to_add)
}