Skip to content

Commit

Permalink
Start working, added projects. WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Eskaan committed Jun 2, 2022
1 parent ca9fb23 commit c690965
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
38 changes: 31 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<project::Project>;

// TODO Search
fn search() -> Result<Vec<project::Project>>;
}

#[derive(thiserror::Error, Debug)]
pub enum Error {}

pub(crate) type Result<T> = std::result::Result<T, Error>;
pub type Datetime = chrono::DateTime<chrono::Utc>;
145 changes: 145 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
/// 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<request::Asset>,
/// If the project allows for distribution
/// Modrinth: Depends on license
pub allows_distribution: bool,
/// The project's authors
pub authors: Vec<Author>,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub enum Type {
Mod,
Modpack,
Ressourcepack,

This comment has been minimized.

Copy link
@blarfoon

blarfoon Jun 2, 2022

Member

You misspelled this

Shader,
Addon,

This comment has been minimized.

Copy link
@blarfoon

blarfoon Jun 2, 2022

Member

Aren't mods/resource packs addons as well?

This comment has been minimized.

Copy link
@Eskaan

Eskaan Jun 2, 2022

Author Contributor

Not on CurseForge, it's a separate Category

This comment has been minimized.

Copy link
@Eskaan

Eskaan Jun 2, 2022

Author Contributor

Not on CurseForge, I just took the main Categories from the API

Plugin
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Links {
///A link to the mod's GitHub page
github: Option<String>,
///A link to the mod's issue tracker
issues: Option<String>,
///A link to the mod's wiki
wiki: Option<String>,
///A link to the mod's discord
discord: Option<String>,
///An array of to the mod's donation platforms
donations: Option<Vec<DonationLink>>,
}

#[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<String>
}

pub trait ProjectTrait {
fn get_body(&self) -> Result<String>;

fn get_versions(&self) -> Result<Vec<Version>>;

fn get_version(&self, id: String) -> Result<Version>;
}
23 changes: 23 additions & 0 deletions src/request.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
/// Description of the asset
description: Option<String>,
/// Headers to send with the request
headers: Option<String>,
/// Request type
request_type: RequestType,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub enum RequestType {
GET,
POST,
PATCH,
DELETE,
}
19 changes: 19 additions & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
@@ -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<ProjectDependency>,
}

/// 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,
}

0 comments on commit c690965

Please sign in to comment.