From aa5505d693887b0bacf1873ce1b21ea6701bbde0 Mon Sep 17 00:00:00 2001 From: Jai A Date: Sun, 31 May 2020 22:20:16 -0700 Subject: [PATCH] Edit CF indexer --- .github/workflows/rust.yml | 2 +- src/routes/mod_editor.rs | 2 +- src/routes/search.rs | 26 +++++++++++++++++++++----- static/css/mod.css | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 20ffefb96..f226295b7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,4 +19,4 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --verbose \ No newline at end of file diff --git a/src/routes/mod_editor.rs b/src/routes/mod_editor.rs index f5903faf8..1c97c3f5d 100644 --- a/src/routes/mod_editor.rs +++ b/src/routes/mod_editor.rs @@ -6,7 +6,7 @@ pub async fn mod_editor_get(hb: web::Data>) -> HttpResponse { let data = json!({ "name": "Handlebars" }); - let body = hb.render("mod_editor", &data).unwrap(); + let body = hb.render("mod-page", &data).unwrap(); HttpResponse::Ok().body(body) } diff --git a/src/routes/search.rs b/src/routes/search.rs index 51c1f8d73..331710aeb 100644 --- a/src/routes/search.rs +++ b/src/routes/search.rs @@ -50,6 +50,7 @@ struct CurseForgeMod { game_version_latest_files: Vec, date_created: String, date_modified: String, + game_slug: String, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -180,12 +181,27 @@ pub async fn index_mods() -> Result<(), Box>{ info!("Indexing curseforge mods!"); - let body = reqwest::get("https://addons-ecs.forgesvc.net/api/v2/addon/search?categoryId=0&gameId=432&index=0&pageSize=10000§ionId=6&sort=5") - .await?.text().await?; + let mut indexing_complete = false; + let mut current_mod_id = 0; + let mut consecutive_returns = 0; - let curseforge_mods: Vec = serde_json::from_str(&body)?; + while !(consecutive_returns > 1000 && current_mod_id > 300000) { + current_mod_id += 1; + info!("Requesting mod with id {} from CurseForge!", current_mod_id); + + let body = reqwest::get(&format!("https://addons-ecs.forgesvc.net/api/v2/addon/{}", current_mod_id)) + .await?.text().await?; + + if body.is_empty() { + consecutive_returns += 1; + continue; + } + + let curseforge_mod : CurseForgeMod = serde_json::from_str(&body)?; + consecutive_returns == 0; + + if curseforge_mod.game_slug != "minecraft" { continue; } - for curseforge_mod in curseforge_mods { let mut mod_game_versions = vec![]; let mut using_forge = false; @@ -298,7 +314,7 @@ pub async fn index_mods() -> Result<(), Box>{ updated: curseforge_mod.date_modified.chars().filter(|c| c.is_ascii_digit()).collect::().parse()?, latest_version, empty: String::from("{}{}{}"), - }) + }); } //Write Indexes diff --git a/static/css/mod.css b/static/css/mod.css index ed6312911..9e52b0f00 100644 --- a/static/css/mod.css +++ b/static/css/mod.css @@ -132,7 +132,7 @@ align-items: center; margin: 30px auto 0 0; - width: 20%; + width: 15%; } .search-bar {