diff --git a/Cargo.lock b/Cargo.lock index fd23df1..fa6d9b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,15 +395,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -445,6 +445,7 @@ dependencies = [ "reqwest", "serde", "serde_json", + "tempfile", "thiserror", "tokio", "toml", @@ -716,15 +717,15 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -901,15 +902,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.1" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d27e9f1..3e3785c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,10 @@ edition = "2021" [dependencies] log = { version = "0.4.21", features = ["serde"] } pretty_env_logger = "0.5.0" -reqwest = "0.11.22" +reqwest = { version = "0.11.22", features = ["json"] } serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.114" +tempfile = "3.10.1" thiserror = "1.0.57" tokio = { version = "1.34.0", features = ["full"] } toml = "0.8.8" diff --git a/config.toml b/config.toml index 5b7d40c..ac739aa 100644 --- a/config.toml +++ b/config.toml @@ -2,7 +2,7 @@ [version] #which version you want? [Vanila, Buckit, Spigot, Paper, Purpur] -core = "Paper" +core = "Vanila" #First: any version if they have. #Second: lock version. (stop update) version = ["1.20.1", false] diff --git a/src/config/mod.rs b/src/config/mod.rs index 8b0f89e..f3efe02 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,15 +1,16 @@ mod datapack; mod errors; -mod model; mod plugin; mod version; +mod models; +use models::{vanila::Vanila, *}; +use tempfile::Builder; use datapack::*; use errors::*; use log::{error, info}; use plugin::Plugin; use serde::{Deserialize, Serialize}; -use std::default; use tokio::fs; use version::Versions; @@ -85,7 +86,7 @@ impl Config { match self.version { //Download purpur Versions::Purpur(ver, freez) => { - if !freez { + if freez { //We don't need to download return Ok(None); } @@ -94,7 +95,7 @@ impl Config { } //Download paper Versions::Paper(ver, freez) => { - if !freez { + if freez { //We don't need to download return Ok(None); } @@ -103,7 +104,7 @@ impl Config { }, //Download Spigot Versions::Spigot(ver, freez) => { - if !freez { + if freez { //We don't need to download return Ok(None); } @@ -112,7 +113,7 @@ impl Config { }, //Download Bucket Versions::Bucket(ver, freez) => { - if !freez { + if freez { //We don't need to download return Ok(None); } @@ -121,12 +122,19 @@ impl Config { }, //Download Vanila Versions::Vanila(ver, freez) => { - if !freez { + if freez { //We don't need to download return Ok(None); } //use if error - Err(DownloadErrors::DownloadCorrapt("ff".to_string())) + // Err(DownloadErrors::DownloadCorrapt("ff".to_string())) + // let tmp_dir = Builder::new().tempdir().map_err(|er| ConfigErrors::LoadCorrapt(er.to_string())); + let _ = match Vanila::find(&*ver).await { + Ok(_) => {}, + Err(e) => {error!("{:#?}", e)}, + }; + + todo!() }, } } diff --git a/src/config/model.rs b/src/config/models/item.rs similarity index 98% rename from src/config/model.rs rename to src/config/models/item.rs index fefbeb6..9af768a 100644 --- a/src/config/model.rs +++ b/src/config/models/item.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use serde::Serialize; use serde_json::Value; -pub type Root = Vec; +pub type ItemRoot = Vec; #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/src/config/models/mod.rs b/src/config/models/mod.rs new file mode 100644 index 0000000..011da40 --- /dev/null +++ b/src/config/models/mod.rs @@ -0,0 +1,2 @@ +pub mod item; +pub mod vanila; \ No newline at end of file diff --git a/src/config/models/vanila.rs b/src/config/models/vanila.rs new file mode 100644 index 0000000..27b43d5 --- /dev/null +++ b/src/config/models/vanila.rs @@ -0,0 +1,74 @@ +use log::info; +use reqwest::Request; +use serde::Deserialize; +use serde::Serialize; + +use crate::config::ConfigErrors; + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Vanila { + pub latest: Latest, + pub versions: Vec, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Latest { + pub release: String, + pub snapshot: String, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Version { + pub id: String, + #[serde(rename = "type")] + #[serde(skip)] + pub type_field: String, + pub url: String, + #[serde(skip)] + pub time: String, + #[serde(skip)] + pub release_time: String, +} + + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct DownloadSection { + pub downloads: Downloads, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Downloads { + pub server: Server, +} + +#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Server { + pub sha1: String, + pub url: String, +} + +impl Vanila { + ///Making request to mojang api and find the link to download minecraft.jar + pub async fn find(version: &str) -> Result<(), ConfigErrors> { + const LINK: &str = "https://piston-meta.mojang.com/v1/packages/8bcd47def18efee744bd0700e86ab44a96ade21f/1.20.4.json"; + let body = match reqwest::get(LINK).await { + Ok(e) => {match e.json::().await { + Ok(e) => {e.downloads.server}, + Err(e) => {Err(ConfigErrors::LoadCorrapt(e.to_string()))}?, + }}, + Err(e) => {Err(ConfigErrors::LoadCorrapt(e.to_string()))}?, + }; + info!("Check body: {:#?}", &body); + Ok(()) + } + + pub async fn download(link: &str) { + todo!() + } +} \ No newline at end of file