From ddde9204c72dd867f920f07f6483be03dda7cf68 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 28 Nov 2022 22:55:14 +0100 Subject: basically update impl; added "good" download; auto dl on new mod; db to 0.4; etc --- src/apis/modrinth.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/apis/modrinth.rs') diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index c99cfbf..7b322cb 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -1,5 +1,6 @@ use std::io::{Error, ErrorKind}; use chrono::{DateTime, FixedOffset}; +use reqwest::Client; use serde::Deserialize; use crate::{Modloader, List}; @@ -113,18 +114,21 @@ pub struct Hash { async fn get(api: String, path: String) -> Result, Box> { let url = format!(r#"{}{}"#, api, path); - dbg!(&url); - - let data = reqwest::get(url) - .await? - .bytes() - .await? - .to_vec(); + let client = Client::builder() + .user_agent(format!("fxqnlr/modlistcli/{} (fxqnlr@gmail.com)", env!("CARGO_PKG_VERSION"))) + .build()?; + let data = client.get(url) + .send() + .await? + .bytes() + .await? + .to_vec(); Ok(data) } pub async fn project(api: String, name: &str) -> Project { + println!("!!!PROJECT"); let url = format!("project/{}", name); let data = get(api, url); @@ -132,9 +136,11 @@ pub async fn project(api: String, name: &str) -> Project { } pub async fn projects(api: String, ids: Vec) -> Vec { + //println!("!!!PROJECTS"); + println!("Getting versions for all mods from modrinth"); let all = ids.join(r#"",""#); let url = format!(r#"projects?ids=["{}"]"#, all); - println!("{}", url); + //println!("{}", url); let data = get(api, url); @@ -142,6 +148,7 @@ pub async fn projects(api: String, ids: Vec) -> Vec { } pub async fn versions(api: String, id: String, list: List) -> Vec { + println!("!!!VERSIONS"); let loaderstr = match list.modloader { Modloader::Forge => String::from("forge"), Modloader::Fabric => String::from("fabric"), @@ -155,6 +162,7 @@ pub async fn versions(api: String, id: String, list: List) -> Vec { } pub async fn get_raw_versions(api: String, versions: Vec) -> Vec { + println!("!!!RAWVERSIONS"); println!("Getting versions {}", &versions.join(", ")); let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); -- cgit v1.2.3