use jiff::Timestamp;
use serde::{Deserialize, Serialize};
use url::Url;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ProjectType {
Mod,
Modpack,
Resourcepack,
Shader,
Plugin,
Datapack,
#[serde(other)]
Unknown,
}
impl ProjectType {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
ProjectType::Mod => "mod",
ProjectType::Modpack => "modpack",
ProjectType::Resourcepack => "resourcepack",
ProjectType::Shader => "shader",
ProjectType::Plugin => "plugin",
ProjectType::Datapack => "datapack",
ProjectType::Unknown => "unknown",
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum ProjectStatus {
Approved,
Archived,
Rejected,
Draft,
Unlisted,
Processing,
Withheld,
Scheduled,
Private,
#[serde(other)]
Unknown,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum RequestedStatus {
Approved,
Archived,
Unlisted,
Private,
Draft,
#[serde(other)]
Unknown,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SideSupport {
Required,
Optional,
Unsupported,
#[serde(other)]
Unknown,
}
impl SideSupport {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
SideSupport::Required => "required",
SideSupport::Optional => "optional",
SideSupport::Unsupported => "unsupported",
SideSupport::Unknown => "unknown",
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct DonationLink {
pub id: String,
pub platform: String,
pub url: Url,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct GalleryImage {
pub url: Url,
pub featured: bool,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub description: Option<String>,
pub created: Timestamp,
#[serde(default)]
pub ordering: Option<i32>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct LicenseRef {
pub id: String,
pub name: String,
#[serde(default)]
pub url: Option<Url>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct ModeratorMessage {
pub message: String,
#[serde(default)]
pub body: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct Project {
pub id: String,
pub slug: String,
pub project_type: ProjectType,
pub team: String,
pub title: String,
pub description: String,
pub body: String,
#[serde(default)]
pub body_url: Option<Url>,
pub published: Timestamp,
pub updated: Timestamp,
#[serde(default)]
pub approved: Option<Timestamp>,
#[serde(default)]
pub queued: Option<Timestamp>,
pub status: ProjectStatus,
#[serde(default)]
pub requested_status: Option<RequestedStatus>,
#[serde(default)]
pub moderator_message: Option<ModeratorMessage>,
pub license: LicenseRef,
pub client_side: SideSupport,
pub server_side: SideSupport,
pub downloads: u64,
pub followers: u64,
#[serde(default)]
pub categories: Vec<String>,
#[serde(default)]
pub additional_categories: Vec<String>,
#[serde(default)]
pub game_versions: Vec<String>,
#[serde(default)]
pub loaders: Vec<String>,
#[serde(default)]
pub versions: Vec<String>,
#[serde(default)]
pub icon_url: Option<Url>,
#[serde(default)]
pub issues_url: Option<Url>,
#[serde(default)]
pub source_url: Option<Url>,
#[serde(default)]
pub wiki_url: Option<Url>,
#[serde(default)]
pub discord_url: Option<Url>,
#[serde(default)]
pub donation_urls: Vec<DonationLink>,
#[serde(default)]
pub gallery: Vec<GalleryImage>,
#[serde(default)]
pub color: Option<u32>,
#[serde(default)]
pub thread_id: Option<String>,
#[serde(default)]
pub monetization_status: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct ProjectValidity {
pub id: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct ProjectDependencies {
pub projects: Vec<Project>,
pub versions: Vec<super::Version>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UploadFile {
pub file_name: String,
pub mime_type: String,
pub bytes: Vec<u8>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl UploadFile {
#[must_use]
pub fn new(file_name: impl Into<String>, mime_type: impl Into<String>, bytes: Vec<u8>) -> Self {
Self {
file_name: file_name.into(),
mime_type: mime_type.into(),
bytes,
}
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
pub struct CreateProjectRequest {
pub slug: String,
pub title: String,
pub description: String,
pub categories: Vec<String>,
pub client_side: SideSupport,
pub server_side: SideSupport,
pub body: String,
pub project_type: ProjectType,
pub license_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub license_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub issues_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wiki_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub discord_url: Option<String>,
#[serde(default)]
pub is_draft: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub initial_versions: Option<Vec<serde_json::Value>>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl CreateProjectRequest {
#[must_use]
pub fn new(
slug: impl Into<String>,
title: impl Into<String>,
description: impl Into<String>,
body: impl Into<String>,
project_type: ProjectType,
license_id: impl Into<String>,
) -> Self {
Self {
slug: slug.into(),
title: title.into(),
description: description.into(),
categories: Vec::new(),
client_side: SideSupport::Optional,
server_side: SideSupport::Optional,
body: body.into(),
project_type,
license_id: license_id.into(),
license_url: None,
issues_url: None,
source_url: None,
wiki_url: None,
discord_url: None,
is_draft: false,
initial_versions: None,
}
}
#[must_use]
pub fn categories(mut self, categories: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.categories = categories.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn client_side(mut self, client_side: SideSupport) -> Self {
self.client_side = client_side;
self
}
#[must_use]
pub fn server_side(mut self, server_side: SideSupport) -> Self {
self.server_side = server_side;
self
}
#[must_use]
pub fn license_url(mut self, url: impl Into<String>) -> Self {
self.license_url = Some(url.into());
self
}
#[must_use]
pub fn issues_url(mut self, url: impl Into<String>) -> Self {
self.issues_url = Some(url.into());
self
}
#[must_use]
pub fn source_url(mut self, url: impl Into<String>) -> Self {
self.source_url = Some(url.into());
self
}
#[must_use]
pub fn wiki_url(mut self, url: impl Into<String>) -> Self {
self.wiki_url = Some(url.into());
self
}
#[must_use]
pub fn discord_url(mut self, url: impl Into<String>) -> Self {
self.discord_url = Some(url.into());
self
}
#[must_use]
pub fn is_draft(mut self, is_draft: bool) -> Self {
self.is_draft = is_draft;
self
}
#[must_use]
pub fn initial_versions(mut self, initial_versions: Vec<serde_json::Value>) -> Self {
self.initial_versions = Some(initial_versions);
self
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
pub struct ModifyProjectRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub slug: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub categories: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_categories: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub client_side: Option<SideSupport>,
#[serde(skip_serializing_if = "Option::is_none")]
pub server_side: Option<SideSupport>,
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<RequestedStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub license_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub license_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub issues_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wiki_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub discord_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub donation_urls: Option<Vec<DonationLink>>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl ModifyProjectRequest {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn slug(mut self, slug: impl Into<String>) -> Self {
self.slug = Some(slug.into());
self
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
#[must_use]
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn categories(mut self, categories: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.categories = Some(categories.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn additional_categories(
mut self,
categories: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.additional_categories = Some(categories.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn client_side(mut self, client_side: SideSupport) -> Self {
self.client_side = Some(client_side);
self
}
#[must_use]
pub fn server_side(mut self, server_side: SideSupport) -> Self {
self.server_side = Some(server_side);
self
}
#[must_use]
pub fn body(mut self, body: impl Into<String>) -> Self {
self.body = Some(body.into());
self
}
#[must_use]
pub fn status(mut self, status: RequestedStatus) -> Self {
self.status = Some(status);
self
}
#[must_use]
pub fn license_id(mut self, license_id: impl Into<String>) -> Self {
self.license_id = Some(license_id.into());
self
}
#[must_use]
pub fn license_url(mut self, url: impl Into<String>) -> Self {
self.license_url = Some(url.into());
self
}
#[must_use]
pub fn issues_url(mut self, url: impl Into<String>) -> Self {
self.issues_url = Some(url.into());
self
}
#[must_use]
pub fn source_url(mut self, url: impl Into<String>) -> Self {
self.source_url = Some(url.into());
self
}
#[must_use]
pub fn wiki_url(mut self, url: impl Into<String>) -> Self {
self.wiki_url = Some(url.into());
self
}
#[must_use]
pub fn discord_url(mut self, url: impl Into<String>) -> Self {
self.discord_url = Some(url.into());
self
}
#[must_use]
pub fn donation_urls(mut self, donation_urls: Vec<DonationLink>) -> Self {
self.donation_urls = Some(donation_urls);
self
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
pub struct BulkEditProjectsRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub categories: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub add_categories: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub remove_categories: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub donation_urls: Option<Vec<DonationLink>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub issues_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub wiki_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub discord_url: Option<String>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl BulkEditProjectsRequest {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn categories(mut self, categories: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.categories = Some(categories.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn add_categories(
mut self,
categories: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.add_categories = Some(categories.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn remove_categories(
mut self,
categories: impl IntoIterator<Item = impl Into<String>>,
) -> Self {
self.remove_categories = Some(categories.into_iter().map(Into::into).collect());
self
}
#[must_use]
pub fn donation_urls(mut self, donation_urls: Vec<DonationLink>) -> Self {
self.donation_urls = Some(donation_urls);
self
}
#[must_use]
pub fn issues_url(mut self, url: impl Into<String>) -> Self {
self.issues_url = Some(url.into());
self
}
#[must_use]
pub fn source_url(mut self, url: impl Into<String>) -> Self {
self.source_url = Some(url.into());
self
}
#[must_use]
pub fn wiki_url(mut self, url: impl Into<String>) -> Self {
self.wiki_url = Some(url.into());
self
}
#[must_use]
pub fn discord_url(mut self, url: impl Into<String>) -> Self {
self.discord_url = Some(url.into());
self
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
pub struct AddGalleryImageRequest {
pub ext: String,
pub featured: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ordering: Option<i32>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl AddGalleryImageRequest {
#[must_use]
pub fn new(ext: impl Into<String>, featured: bool) -> Self {
Self {
ext: ext.into(),
featured,
title: None,
description: None,
ordering: None,
}
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
#[must_use]
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn ordering(mut self, ordering: i32) -> Self {
self.ordering = Some(ordering);
self
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
pub struct ModifyGalleryImageRequest {
pub url: Url,
#[serde(skip_serializing_if = "Option::is_none")]
pub featured: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ordering: Option<i32>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl ModifyGalleryImageRequest {
#[must_use]
pub fn new(url: Url) -> Self {
Self {
url,
featured: None,
title: None,
description: None,
ordering: None,
}
}
#[must_use]
pub fn featured(mut self, featured: bool) -> Self {
self.featured = Some(featured);
self
}
#[must_use]
pub fn title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
#[must_use]
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
#[must_use]
pub fn ordering(mut self, ordering: i32) -> Self {
self.ordering = Some(ordering);
self
}
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Serialize, Eq, PartialEq)]
pub struct ScheduleProjectRequest {
pub time: Timestamp,
pub requested_status: RequestedStatus,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl ScheduleProjectRequest {
#[must_use]
pub fn new(time: Timestamp, requested_status: RequestedStatus) -> Self {
Self {
time,
requested_status,
}
}
}