Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
add find fn for vanila
Browse files Browse the repository at this point in the history
  • Loading branch information
TOwInOK committed Mar 2, 2024
1 parent 930c4e0 commit d0d3f8a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 22 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 16 additions & 8 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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!()
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/model.rs → src/config/models/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;

pub type Root = Vec<ItemData>;
pub type ItemRoot = Vec<ItemData>;

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down
2 changes: 2 additions & 0 deletions src/config/models/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod item;
pub mod vanila;
74 changes: 74 additions & 0 deletions src/config/models/vanila.rs
Original file line number Diff line number Diff line change
@@ -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<Version>,
}

#[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::<DownloadSection>().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!()
}
}

0 comments on commit d0d3f8a

Please sign in to comment.