ferinth/structures/
version.rs

1//! Models related to versions
2//!
3//! [documentation](https://docs.modrinth.com/api-spec/#tag/version_model)
4
5use super::*;
6
7#[derive(Deserialize, Serialize, Debug, Clone)]
8pub struct Version {
9    pub name: String,
10    /// Ideally will follow semantic versioning
11    pub version_number: String,
12    pub changelog: Option<String>,
13    pub dependencies: Vec<Dependency>,
14    pub game_versions: Vec<String>,
15    /// The release channel for this version
16    pub version_type: VersionType,
17    pub loaders: Vec<String>,
18    pub featured: bool,
19    pub status: Option<Status>,
20    pub requested_status: Option<RequestedStatus>,
21    pub id: ID,
22    pub project_id: ID,
23    /// The user ID of the author who published this version
24    pub author_id: ID,
25    pub date_published: UtcTime,
26    pub downloads: Int,
27    /// A list of files available for download
28    pub files: Vec<VersionFile>,
29}
30
31#[derive(Deserialize, Serialize, Debug, Clone)]
32pub struct VersionFile {
33    pub hashes: Hash,
34    pub url: Url,
35    pub filename: String,
36    /// Whether the file is the primary file of its version
37    ///
38    /// There can only be a maximum of one primary file per version.
39    /// If there are no primary files specified, the first file can be taken as the primary one.
40    pub primary: bool,
41    /// The size of the file in bytes
42    pub size: Int,
43    /// The type of the additional file, used mainly for adding resource packs to datapacks
44    pub file_type: Option<AdditionalFileType>,
45}
46
47#[derive(Deserialize, Serialize, Debug, Clone)]
48pub struct Hash {
49    pub sha512: String,
50    pub sha1: String,
51    /// Other hashes that may have been provided
52    #[serde(flatten)]
53    pub others: std::collections::HashMap<String, String>,
54}
55
56#[derive(Deserialize, Serialize, Debug, Clone)]
57pub struct LatestVersionBody {
58    pub loaders: Vec<String>,
59    pub game_versions: Vec<String>,
60}
61
62#[derive(Deserialize, Serialize, Debug, Clone)]
63pub struct LatestVersionsBody {
64    pub hashes: Vec<String>,
65    pub algorithm: HashAlgorithm,
66    pub loaders: Vec<String>,
67    pub game_versions: Vec<String>,
68}
69
70#[derive(Serialize, Deserialize, Clone, Debug)]
71pub struct Dependency {
72    pub version_id: Option<ID>,
73    pub project_id: Option<ID>,
74    pub file_name: Option<String>,
75    pub dependency_type: DependencyType,
76}
77
78#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq)]
79#[serde(rename_all = "lowercase")]
80pub enum HashAlgorithm {
81    SHA512,
82    SHA1,
83}
84
85#[derive(Deserialize, Serialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
86#[serde(rename_all = "lowercase")]
87pub enum VersionType {
88    Release,
89    Beta,
90    Alpha,
91}
92
93#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
94#[serde(rename_all = "lowercase")]
95pub enum DependencyType {
96    Required,
97    Optional,
98    Incompatible,
99    Embedded,
100}
101
102#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
103#[serde(rename_all = "lowercase")]
104pub enum Status {
105    Listed,
106    Archived,
107    Draft,
108    Unlisted,
109    Scheduled,
110    Unknown,
111}
112
113#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
114#[serde(rename_all = "lowercase")]
115pub enum RequestedStatus {
116    Listed,
117    Archived,
118    Draft,
119    Unlisted,
120}
121
122#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
123#[serde(rename_all = "kebab-case")]
124pub enum AdditionalFileType {
125    RequiredResourcePack,
126    OptionalResourcePack,
127}