diff --git a/src/main.rs b/src/main.rs index 4be72be9a..2badbecde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ async fn main() -> std::io::Result<()> { let handlebars_ref = web::Data::new(handlebars); let database = database::connect(); - routes::index_mods(database); + routes::index_mods(database).await; //Init App HttpServer::new(move || { diff --git a/src/routes/search.rs b/src/routes/search.rs index e1509bff1..6cee8904a 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -4,6 +4,7 @@ use actix_web::{web, web::Data, HttpRequest, HttpResponse, get, post}; use handlebars::*; use meilisearch_sdk::{document::*, indexes::*, client::*, search::*}; use serde::{Serialize, Deserialize}; +use actix_web::client; use crate::database::*; use diesel::prelude::*; @@ -91,7 +92,7 @@ fn search(web::Query(info): web::Query) -> Vec { client.get_index("mods").unwrap().search::(&query).unwrap().hits } -pub fn index_mods(conn : PgConnection) { +pub async fn index_mods(conn : PgConnection) { use crate::schema::mods::dsl::*; use crate::schema::versions::dsl::*; @@ -119,5 +120,18 @@ pub fn index_mods(conn : PgConnection) { }); } + let mut client = client::Client::default(); + + let mut response = client.get("https://addons-ecs.forgesvc.net/api/v2/addon/search?categoryId=0&gameId=432&index=0&pageSize=100§ionId=6&sort=5") + .header("User-Agent", "Actix-web") + .header("Content-Type", "application/json") + .send().await.unwrap(); + + println!("{:?}", response); + + let body = response.body().await.unwrap(); + println!("Downloaded: {:?} bytes", body); + + mods_index.add_documents(docs_to_add, Some("mod_id")).unwrap(); } \ No newline at end of file