-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 🚧 restructure current code
- Loading branch information
Showing
17 changed files
with
477 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[env] | ||
CURSE_API_TOKEN = "$2a$10$FSMPrnX2TyC9kluMfAWvHuGqGxa7qKuvXpClTB/vB8LE3fVu9ic9e" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const TOKEN: &str = env!("CURSE_API_TOKEN"); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::errors::CreatorError; | ||
|
||
use super::{CurseApi, CURSE_API_URL}; | ||
use serde::Deserialize; | ||
use time::OffsetDateTime; | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct MinecraftVersion { | ||
pub id: u32, | ||
pub game_version_id: u32, | ||
pub version_string: String, | ||
pub jar_download_url: String, | ||
pub json_download_url: String, | ||
pub approved: bool, | ||
#[serde(with = "time::serde::rfc3339")] | ||
pub date_modified: OffsetDateTime, | ||
pub game_version_type_id: u32, | ||
pub game_version_status: u32, | ||
pub game_version_type_status: u32, | ||
} | ||
|
||
#[derive(Debug, serde::Deserialize)] | ||
pub struct MinecraftVersionsList { | ||
pub data: Vec<MinecraftVersion> | ||
} | ||
|
||
impl CurseApi { | ||
pub async fn get_minecraft_versions(&self) -> Result<MinecraftVersionsList, CreatorError> { | ||
let versions = self.http_client.get(format!("{}{}", CURSE_API_URL, "minecraft/version").as_str()) | ||
.send() | ||
.await? | ||
.json::<MinecraftVersionsList>() | ||
.await?; | ||
|
||
Ok(versions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use reqwest::header::HeaderMap; | ||
|
||
use crate::errors::CreatorError; | ||
|
||
mod minecraft; | ||
mod modloader; | ||
|
||
pub static CURSE_API_URL: &str = "https://api.curseforge.com/v1/"; | ||
|
||
pub struct CurseApi { | ||
http_client: reqwest::Client, | ||
} | ||
|
||
impl CurseApi { | ||
pub fn new<S>(api_token: S) -> Result<Self, CreatorError> | ||
where | ||
S: AsRef<str>, | ||
{ | ||
let mut headers = HeaderMap::new(); | ||
headers.insert("X-Api-Key", api_token.as_ref().parse().unwrap()); | ||
|
||
let http_client = reqwest::Client::builder() | ||
.default_headers(headers) | ||
.build()?; | ||
|
||
Ok(Self { http_client }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use super::CurseApi; | ||
|
||
impl CurseApi { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum CreatorError { | ||
#[error("Invalid Mod Loader")] | ||
InvalidModLoader, | ||
|
||
#[error("Invalid Minecraft Version")] | ||
InvalidMinecraftVersion, | ||
|
||
#[error("Prompt Error: {0}")] | ||
PromptError(requestty::ErrorKind), | ||
|
||
#[error("IO Error: {0}")] | ||
IoError(std::io::Error), | ||
|
||
#[error("{0}")] | ||
HttpError(reqwest::Error) | ||
} | ||
|
||
impl From<requestty::ErrorKind> for CreatorError { | ||
fn from(err: requestty::ErrorKind) -> Self { | ||
CreatorError::PromptError(err) | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for CreatorError { | ||
fn from(err: std::io::Error) -> Self { | ||
CreatorError::IoError(err) | ||
} | ||
} | ||
|
||
impl From<reqwest::Error> for CreatorError { | ||
fn from(err: reqwest::Error) -> Self { | ||
CreatorError::HttpError(err) | ||
} | ||
} |
Oops, something went wrong.