From c690965f4c02536ceb18ae631501d82b156f1238 Mon Sep 17 00:00:00 2001 From: Code-Ac Date: Thu, 2 Jun 2022 19:40:10 +0200 Subject: [PATCH] Start working, added projects. WIP --- Cargo.toml | 3 + src/lib.rs | 38 ++++++++++--- src/project.rs | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ src/request.rs | 23 ++++++++ src/version.rs | 19 +++++++ 5 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 src/project.rs create mode 100644 src/request.rs create mode 100644 src/version.rs diff --git a/Cargo.toml b/Cargo.toml index ece1d2c..e443d10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = { version = "0", features = ["serde"] } +serde = { version = "1", features = ["derive"] } +thiserror = "1" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1b4a90c..8f88ca2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,32 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } +//! # Dotium +//! +//! Dotium is the uniform object provider for Minecraft Mod hosting platforms, +//! who get traits in Libraries like Ferinth and Furse to then be used platform independedly in Libium. +//! +use serde::{Deserialize, Serialize}; + +pub mod project; +pub mod request; +pub mod version; + +pub struct Platform { + /// The name of the platform + name: String, + /// The two-letter nick name of the Platform + short_name: String, + /// Logo of the platform + logo: request::Asset, } + +pub trait PlatformTrait { + fn get_project(id: String) -> Result; + + // TODO Search + fn search() -> Result>; +} + +#[derive(thiserror::Error, Debug)] +pub enum Error {} + +pub(crate) type Result = std::result::Result; +pub type Datetime = chrono::DateTime; diff --git a/src/project.rs b/src/project.rs new file mode 100644 index 0000000..80d7373 --- /dev/null +++ b/src/project.rs @@ -0,0 +1,145 @@ +use crate::version::Version; + +use super::*; + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Project { + /// The project's ID + pub id: String, + /// The project's slug + pub slug: String, + /// The project's type + pub project_type: Type, + /// The project's Name + pub name: String, + /// The Description of the project + pub description: String, + /// Links to external project pages + pub links: Links, + /// Requirements on server and/or client + pub requirements: Requirement, + /// The project's categories + // TODO: Icons, not only the names + pub categories: Vec, + /// Download count of the project + pub downloads: i64, + /// The count of the current project followers + /// CurseForge: Thumbs up count + pub followers: i32, + /// Icon of the project + pub icon: request::Asset, + /// The current status of approval for the mod + pub status: Status, + /// The date when the project was published + /// Curseforge: Date released + pub published: Datetime, + /// The date the project was last updated + pub updated: Datetime, + /// The date the project was created + pub created: Datetime, + /// A mod's pictures / gallery + pub gallery: Vec, + /// If the project allows for distribution + /// Modrinth: Depends on license + pub allows_distribution: bool, + /// The project's authors + pub authors: Vec, +} + +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub enum Type { + Mod, + Modpack, + Ressourcepack, + Shader, + Addon, + Plugin +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Links { + ///A link to the mod's GitHub page + github: Option, + ///A link to the mod's issue tracker + issues: Option, + ///A link to the mod's wiki + wiki: Option, + ///A link to the mod's discord + discord: Option, + ///An array of to the mod's donation platforms + donations: Option>, +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct DonationLink { + ///The platform ID + id: String, + ///The platform name + platform: String, + ///The link to the donations page of the platform + url: String, +} + +/// Requirements of a projects, for server and Client +/// Modrinth only, CF will show up as Unkown +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct ProjectRequirements { + server: Requirement, + client: Requirement, +} + +/// Requirement status +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub enum Requirement { + Required, + Optional, + Unsupported, + Unkown, +} + +/// Status of a Project +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub enum Status { + /// Modrinth: Draft + New, + /// Modrinth only + Unlisted, + /// CurseForge only + ChangesRequired, + /// CurseForge only + UnderSoftReview, + /// Modrinth: Approved + Approved, + /// Modrinth: Rejected + Rejected, + /// CurseForge only + ChangesMade, + /// CurseForge only + Inactive, + /// Modrinth: Archived + Abandoned, + /// Modrinth: Unkown + Deleted, + /// Modrinth: Processing + UnderReview, +} + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Author { + /// The unique username of the user + username: String, + /// The display name of the user + name: String, + // The ID of the user + id: String, + /// The Avatar URL of the user + avatar_url: Option +} + +pub trait ProjectTrait { + fn get_body(&self) -> Result; + + fn get_versions(&self) -> Result>; + + fn get_version(&self, id: String) -> Result; +} diff --git a/src/request.rs b/src/request.rs new file mode 100644 index 0000000..0498b7c --- /dev/null +++ b/src/request.rs @@ -0,0 +1,23 @@ +use super::*; + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Asset { + /// The request URL + url: String, + /// Name of the asset + name: Option, + /// Description of the asset + description: Option, + /// Headers to send with the request + headers: Option, + /// Request type + request_type: RequestType, +} + +#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] +pub enum RequestType { + GET, + POST, + PATCH, + DELETE, +} diff --git a/src/version.rs b/src/version.rs new file mode 100644 index 0000000..e5f0169 --- /dev/null +++ b/src/version.rs @@ -0,0 +1,19 @@ +use super::*; + +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct Version { + /// The ID of the version + id: String, + + /// Dependencies on other projects + pub dependencies: Vec, +} + +/// Dependency on a Project's version +#[derive(Deserialize, Serialize, Debug, Clone)] +pub struct ProjectDependency { + //The ID of the project to depend on + project_id: String, + //The version of the project it depends on + version: Version, +}