packrinth 0.8.3

CLI tool for creating and maintaining your own Minecraft modpack
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
//! Structs that are only used for (de)serializing JSONs associated with Modrinth.

use crate::config::{BranchConfig, IncludeOrExclude, Loader, ProjectSettings};
use crate::{MRPACK_INDEX_FILE_NAME, PackrinthError, PackrinthResult};
use serde::{Deserialize, Serialize};
use std::io::{BufReader, Read};
use std::path::Path;
use std::{cmp, fs, io};
use zip::ZipArchive;
use zip::result::ZipResult;

const MODRINTH_API_BASE_URL: &str = "https://api.modrinth.com/v2";

/// Extract all the contents of a Modrinth modpack, except for the main manifest file.
///
/// # Errors
/// An [`Err`] is returned when one of these things go wrong:
/// - Failed to open file
/// - Failed to start zip archive
/// - Failed to get file by index
/// - Failed to create dirs
/// - Failed to copy file
pub fn extract_mrpack_overrides(mrpack_path: &Path, output_directory: &Path) -> ZipResult<()> {
    let zip_file = fs::File::open(mrpack_path)?;
    let mut archive = ZipArchive::new(zip_file)?;

    for i in 0..archive.len() {
        let mut file = archive.by_index(i)?;
        let output_path = Path::new(output_directory).join(file.name());

        if file.name().ends_with('/') {
            // It's a directory
            fs::create_dir_all(&output_path)?;
        } else if file.name() != MRPACK_INDEX_FILE_NAME {
            // Make sure parent dirs exist
            if let Some(parent) = output_path.parent()
                && !parent.exists()
            {
                fs::create_dir_all(parent)?;
            }
            // Copy file contents
            let mut output_file = fs::File::create(&output_path)?;
            io::copy(&mut file, &mut output_file)?;
        }
    }

    Ok(())
}

fn request_text<T: ToString>(api_endpoint: &T) -> PackrinthResult<String> {
    let full_url = MODRINTH_API_BASE_URL.to_string() + api_endpoint.to_string().as_str();
    crate::request_text(&full_url)
}

/// Part of the fields returned from the `/project` Modrinth API endpoint (v2).
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Project {
    pub id: String,
    pub slug: String,
    pub title: String,
    pub server_side: SideSupport,
    pub client_side: SideSupport,
    pub project_type: ProjectType,
}

/// The type of project.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ProjectType {
    #[serde(rename = "mod")]
    Mod,

    #[serde(rename = "modpack")]
    Modpack,

    #[serde(rename = "resourcepack")]
    ResourcePack,

    #[serde(rename = "shader")]
    Shader,
}

/// The support for a specific environment (server or client).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum SideSupport {
    #[serde(rename = "required")]
    Required,

    #[serde(rename = "optional")]
    Optional,

    #[serde(rename = "unsupported")]
    Unsupported,
}

/// Part of the fields returned from the `/version` Modrinth API endpoint (v2).
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Version {
    pub id: String,
    pub project_id: String,
    pub version_type: VersionType,
    pub game_versions: Vec<String>,
    pub files: Vec<VersionFile>,
    pub dependencies: Vec<VersionDependency>,
}

/// Type of version.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum VersionType {
    #[serde(rename = "release")]
    Release,

    #[serde(rename = "beta")]
    Beta,

    #[serde(rename = "alpha")]
    Alpha,
}

/// File in a version.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct VersionFile {
    pub url: String,
    pub filename: String,
    pub primary: bool,
    pub size: u64,
    pub hashes: FileHashes,
}

/// Hashes for a file.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct FileHashes {
    pub sha1: String,
    pub sha512: String,
}

/// Dependency for a version.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct VersionDependency {
    pub project_id: Option<String>,
    pub dependency_type: VersionDependencyType,
}

/// Type of version dependency.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum VersionDependencyType {
    #[serde(rename = "required")]
    Required,

    #[serde(rename = "optional")]
    Optional,

    #[serde(rename = "incompatible")]
    Incompatible,

    #[serde(rename = "embedded")]
    Embedded,
}

/// The main index file in a Modrinth modpack.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MrPack {
    pub format_version: u16,
    pub game: String,
    pub version_id: String,
    pub name: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub summary: Option<String>,

    pub files: Vec<File>,
    pub dependencies: MrPackDependencies,
}

/// A file in a modpack.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct File {
    #[serde(skip_serializing)]
    #[serde(skip_deserializing)]
    pub project_name: String,

    pub path: String,
    pub hashes: FileHashes,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub env: Option<Env>,

    pub downloads: Vec<String>,
    pub file_size: u64,
}

/// Environment information for a file in a Modrinth modpack.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Env {
    pub client: SideSupport,
    pub server: SideSupport,
}

/// Dependencies for a modpack, which are mod loaders that get installed alongside the modpack.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MrPackDependencies {
    pub minecraft: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub forge: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub neoforge: Option<String>,

    #[serde(rename = "fabric-loader")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub fabric_loader: Option<String>,

    #[serde(rename = "quilt-loader")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quilt_loader: Option<String>,
}

/// The result of creating a file.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FileResult {
    Ok {
        file: File,
        dependencies: Vec<VersionDependency>,
        project_id: String,
    },
    Skipped,
    NotFound,
    Err(PackrinthError),
}

impl Project {
    /// Gets a project from the Modrinth ID.
    ///
    /// # Errors
    /// - [`PackrinthError::RequestFailed`] if the Modrinth request failed
    /// - [`PackrinthError::FailedToParseConfigJson`] if the Modrinth response was invalid
    pub fn from_id(id: &str) -> PackrinthResult<Self> {
        // Request to get general information about the project associated with the version
        let api_endpoint = format!("/project/{id}");
        let modrinth_project_response = request_text(&api_endpoint)?;
        match serde_json::from_str::<Self>(&modrinth_project_response) {
            Ok(versions) => Ok(versions),
            Err(error) => Err(PackrinthError::FailedToParseModrinthResponseJson {
                modrinth_endpoint: api_endpoint,
                error_message: error.to_string(),
            }),
        }
    }
}

impl ProjectType {
    /// Returns the directory name of where the project would go in to.
    ///
    /// # Errors
    /// - [`PackrinthError::AttemptedToAddOtherModpack`] when [`ProjectType`] is [`ProjectType::Modpack`]
    pub fn directory(&self) -> PackrinthResult<&str> {
        match self {
            ProjectType::Mod => Ok("mods"),

            // This happens when you add a modpack as project.
            ProjectType::Modpack => Err(PackrinthError::AttemptedToAddOtherModpack),

            ProjectType::ResourcePack => Ok("resourcepacks"),
            ProjectType::Shader => Ok("shaderpacks"),
        }
    }
}

impl Version {
    /// Fetches a [`Version`] from a sha512 hash.
    ///
    /// # Errors
    /// - [`PackrinthError::FailedToParseModrinthResponseJson`] if the response was invalid
    pub fn from_sha512_hash(hash: &str) -> PackrinthResult<Self> {
        let api_endpoint = format!("/version_file/{hash}?algorithm=sha512");
        let api_response = request_text(&api_endpoint)?;

        match serde_json::from_str::<Self>(&api_response) {
            Ok(versions) => Ok(versions),
            Err(error) => Err(PackrinthError::FailedToParseModrinthResponseJson {
                modrinth_endpoint: api_endpoint,
                error_message: error.to_string(),
            }),
        }
    }
}

impl MrPack {
    /// Creates a [`MrPack`] instance from a `.mrpack` file location.
    ///
    /// # Errors
    /// - [`PackrinthError::FailedToInitializeFileType`] when creating the `.mrpack` file type failed
    /// - [`PackrinthError::FailedToCreateZipArchive`] when creating the zip archive failed
    /// - [`PackrinthError::InvalidMrPack`] when the modpack doesn't fully adhere to the mrpack specifications
    /// - [`PackrinthError::FailedToReadToString`] when reading the main config in the zip failed
    pub fn from_mrpack(mrpack_path: &Path) -> PackrinthResult<Self> {
        let mrpack_file = match fs::File::open(mrpack_path) {
            Ok(mrpack_file) => mrpack_file,
            Err(error) => {
                return Err(PackrinthError::FailedToInitializeFileType {
                    file_to_create: mrpack_path.display().to_string(),
                    error_message: error.to_string(),
                });
            }
        };
        let mut zip_archive = match ZipArchive::new(BufReader::new(mrpack_file)) {
            Ok(zip_archive) => zip_archive,
            Err(error) => {
                return Err(PackrinthError::FailedToCreateZipArchive {
                    zip_path: mrpack_path.display().to_string(),
                    error_message: error.to_string(),
                });
            }
        };

        let mut mrpack_config_file = match zip_archive.by_name(MRPACK_INDEX_FILE_NAME) {
            Ok(mrpack_config_file_name) => mrpack_config_file_name,
            Err(error) => {
                return Err(PackrinthError::InvalidMrPack {
                    mrpack_path: mrpack_path.display().to_string(),
                    error_message: error.to_string(),
                });
            }
        };
        let mut mrpack = String::new();
        if let Err(error) = mrpack_config_file.read_to_string(&mut mrpack) {
            return Err(PackrinthError::FailedToReadToString {
                path_to_read: mrpack_config_file.name().to_string(),
                error_message: error.to_string(),
            });
        }

        match serde_json::from_str(&mrpack) {
            Ok(mrpack) => Ok(mrpack),
            Err(error) => Err(PackrinthError::InvalidMrPack {
                mrpack_path: mrpack_path.display().to_string(),
                error_message: error.to_string(),
            }),
        }
    }
}

impl File {
    /// Creates a file type from a project.
    #[must_use]
    pub fn from_project(
        branch_name: &str,
        branch_config: &BranchConfig,
        project_id: &str,
        project_settings: &ProjectSettings,
        no_alpha: bool,
        no_beta: bool,
    ) -> FileResult {
        // Handle inclusions and exclusions
        if let Some(include_or_exclude) = &project_settings.include_or_exclude {
            match include_or_exclude {
                IncludeOrExclude::Include(inclusions) => {
                    if !inclusions.contains(&branch_name.to_string()) {
                        return FileResult::Skipped;
                    }
                }
                IncludeOrExclude::Exclude(exclusions) => {
                    if exclusions.contains(&branch_name.to_string()) {
                        return FileResult::Skipped;
                    }
                }
            }
        }

        let mut loaders = Loader::modrinth_value_vec(&branch_config.acceptable_loaders);
        if let Some(mod_loader) = &branch_config.mod_loader {
            loaders.push(mod_loader.modrinth_value());
        }

        // Default loaders that will always be added
        loaders.push(Loader::Minecraft.modrinth_value());
        loaders.push(Loader::VanillaShader.modrinth_value());

        // Always add main minecraft version to acceptable minecraft versions
        let mut game_versions = vec![branch_config.minecraft_version.clone()];
        game_versions.extend(branch_config.acceptable_minecraft_versions.clone());

        let mut api_endpoint = format!(
            "/project/{project_id}/version?loaders={loaders:?}&game_versions={game_versions:?}"
        );

        // Used to know if endpoint will return ONE version or a list of versions
        let mut is_version_override = false;

        // Change endpoint to version if an override is provided for this branch
        if let Some(version_overrides) = &project_settings.version_overrides
            && let Some(version_override) = version_overrides.get(branch_name)
        {
            api_endpoint = format!("/version/{version_override}");
            is_version_override = true;
        }

        let api_response = match request_text(&api_endpoint) {
            Ok(response) => response,
            Err(error) => return FileResult::Err(error),
        };
        let mut modrinth_versions: Vec<Version> = if is_version_override {
            match serde_json::from_str::<Version>(&api_response) {
                Ok(version) => vec![version],
                Err(error) => {
                    return FileResult::Err(PackrinthError::FailedToParseModrinthResponseJson {
                        modrinth_endpoint: api_endpoint,
                        error_message: error.to_string(),
                    });
                }
            }
        } else {
            match serde_json::from_str(&api_response) {
                Ok(versions) => versions,
                Err(error) => {
                    return FileResult::Err(PackrinthError::FailedToParseModrinthResponseJson {
                        modrinth_endpoint: api_endpoint,
                        error_message: error.to_string(),
                    });
                }
            }
        };

        // It is not confusing in this context.
        #[allow(clippy::items_after_statements)]
        fn max_semver(versions: &[String]) -> Option<semver::Version> {
            versions
                .iter()
                .filter_map(|s| s.parse::<semver::Version>().ok())
                .max()
        }

        modrinth_versions.sort_by(|a, b| {
            let ma = max_semver(&a.game_versions);
            let mb = max_semver(&b.game_versions);
            match (ma, mb) {
                (Some(va), Some(vb)) => cmp::Reverse(va).cmp(&cmp::Reverse(vb)),
                (Some(_), None) => cmp::Ordering::Less,
                (None, Some(_)) => cmp::Ordering::Greater,
                (None, None) => cmp::Ordering::Equal,
            }
        });
        for modrinth_version in modrinth_versions {
            match modrinth_version.version_type {
                VersionType::Release => return Self::from_modrinth_version(&modrinth_version),
                VersionType::Beta => {
                    if !no_beta {
                        return Self::from_modrinth_version(&modrinth_version);
                    }
                }
                VersionType::Alpha => {
                    if !no_alpha {
                        return Self::from_modrinth_version(&modrinth_version);
                    }
                }
            }
        }

        // If no versions were returned in the for loop.
        FileResult::NotFound
    }

    fn from_modrinth_version(modrinth_version: &Version) -> FileResult {
        // Request to get general information about the project associated with the version
        let modrinth_project: Project = match Project::from_id(&modrinth_version.project_id) {
            Ok(versions) => versions,
            Err(error) => {
                return FileResult::Err(error);
            }
        };

        // Get the primary file. Every version should have one.
        let mut primary_file_url = None;
        let mut primary_file_name = None;
        let mut primary_file_hashes = None;
        let mut primary_file_size = None;
        for version_file in &modrinth_version.files {
            if version_file.primary {
                primary_file_url = Some(&version_file.url);
                primary_file_name = Some(&version_file.filename);
                primary_file_hashes = Some(&version_file.hashes);
                primary_file_size = Some(&version_file.size);
                break;
            }
        }
        if primary_file_url.is_none() {
            primary_file_url = Some(&modrinth_version.files[0].url);
        }
        if primary_file_name.is_none() {
            primary_file_name = Some(&modrinth_version.files[0].filename);
        }
        if primary_file_hashes.is_none() {
            primary_file_hashes = Some(&modrinth_version.files[0].hashes);
        }
        if primary_file_size.is_none() {
            primary_file_size = Some(&modrinth_version.files[0].size);
        }

        let directory = match modrinth_project.project_type.directory() {
            Ok(directory) => directory,
            Err(error) => return FileResult::Err(error),
        };

        // Always use / as file separator, because all MrPacks should use this (even on Windows).
        let path =
            String::from(directory) + "/" + primary_file_name.expect("No Modrinth file found");

        FileResult::Ok {
            file: Self {
                project_name: modrinth_project.title,
                path,
                hashes: primary_file_hashes.expect("No Modrinth file found").clone(),
                env: Some(Env {
                    client: modrinth_project.client_side,
                    server: modrinth_project.server_side,
                }),
                downloads: vec![primary_file_url.expect("No Modrinth file found").clone()],
                file_size: *primary_file_size.expect("No Modrinth file found"),
            },
            dependencies: modrinth_version.dependencies.clone(),
            project_id: modrinth_version.project_id.clone(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::config::MainLoader;
    use pretty_assertions::assert_eq;

    #[test]
    fn project_from_id() {
        let project = Project::from_id("fabric-api");
        assert_eq!(
            Ok(Project {
                id: "P7dR8mSH".to_string(),
                slug: "fabric-api".to_string(),
                title: "Fabric API".to_string(),
                server_side: SideSupport::Optional,
                client_side: SideSupport::Optional,
                project_type: ProjectType::Mod,
            }),
            project
        );
    }

    #[test]
    fn test_version_from_sha512_hash() {
        let version = Version::from_sha512_hash(
            "f0ecb1e1c8f1471437c83f4f58e549efecc0ed3f275baa2a64bbb9a26fd8c14365431bf92cf68d8f8055f6ef103fcc863cd75adbbe8be80f7b752fe1c0c3a305",
        );
        println!("{:#?}", version);
        assert_eq!(Ok(Version {
            id: "9xIK4e8l".to_string(),
            project_id: "P7dR8mSH".to_string(),
            version_type: VersionType::Release,
            game_versions: vec!["1.21.1".to_string()],
            files: vec![VersionFile {
                url: "https://cdn.modrinth.com/data/P7dR8mSH/versions/9xIK4e8l/fabric-api-0.116.6%2B1.21.1.jar".to_string(),
                filename: "fabric-api-0.116.6+1.21.1.jar".to_string(),
                primary: true,
                size: 2424827,
                hashes: FileHashes { sha1: "10d5c7cf5fb309513b4f68b85b1e0d9dccbec9ac".to_string(), sha512: "f0ecb1e1c8f1471437c83f4f58e549efecc0ed3f275baa2a64bbb9a26fd8c14365431bf92cf68d8f8055f6ef103fcc863cd75adbbe8be80f7b752fe1c0c3a305".to_string() },
            }],
            dependencies: vec![],
        }), version);
    }

    // TODO add tests for MrPack struct

    #[test]
    fn test_file_from_project() {
        let branch_config = BranchConfig {
            version: "1.0.0".to_string(),
            minecraft_version: "1.14".to_string(),
            acceptable_minecraft_versions: vec![],
            mod_loader: Some(MainLoader::Fabric),
            loader_version: Some("0.17.2".to_string()),
            acceptable_loaders: vec![],
            manual_files: vec![],
        };
        let project_settings = ProjectSettings {
            version_overrides: None,
            include_or_exclude: None,
        };
        let file = File::from_project(
            "test",
            &branch_config,
            "fabric-api",
            &project_settings,
            false,
            false,
        );
        assert_eq!(FileResult::Ok {
            file: File {
                project_name: "Fabric API".to_string(),
                path: "mods/fabric-0.2.7%2Bbuild.127.jar".to_string(),
                hashes: FileHashes { sha1: "554edd4ffb7c05585acc8b7700f523e4b1fc0cde".to_string(), sha512: "6fc41a2adaa4d3b254cb378ec2fbe589d178d998516cf6e7abed8ad4a3fa9da7e75201dcf843698917f1f3b2fb5458587426b79ae22bc642774fc74ff38e79d6".to_string() },
                env: Some(Env {
                    client: SideSupport::Optional,
                    server: SideSupport::Optional,
                }),
                downloads: vec!["https://cdn.modrinth.com/data/P7dR8mSH/versions/0.2.7%2Bbuild.127/fabric-0.2.7%2Bbuild.127.jar".to_string(),],
                file_size: 253237,
            },
            dependencies: vec![],
            project_id: "P7dR8mSH".to_string(),
        }, file);
    }

    #[test]
    fn test_file_from_modrinth_version() {
        let modrinth_version = Version {
            id: "X2hTodix".to_string(),
            project_id: "P7dR8mSH".to_string(),
            version_type: VersionType::Release,
            game_versions: vec!["1.21.8".to_string()],
            files: vec![VersionFile {
                url: "https://cdn.modrinth.com/data/P7dR8mSH/versions/X2hTodix/fabric-api-0.129.0%2B1.21.8.jar".to_string(),
                filename: "fabric-api-0.129.0+1.21.8.jar".to_string(),
                primary: true,
                size: 2_212_412,
                hashes: FileHashes { sha1: "9be74f9c3120ffb9f38df8f4164392d69e6ba84e".to_string(), sha512: "471babff84b36bd0f5051051bc192a97136ba733df6a49f222cb67a231d857eb4b1c5ec8dea605e146f49f75f800709f8836540a472fe8032f9fbd3f6690ec3d".to_string() },
            }],
            dependencies: vec![],
        };
        let file = File::from_modrinth_version(&modrinth_version);
        assert_eq!(FileResult::Ok {
            file: File {
                project_name: "Fabric API".to_string(),
                path: "mods/fabric-api-0.129.0+1.21.8.jar".to_string(),
                hashes: FileHashes { sha1: "9be74f9c3120ffb9f38df8f4164392d69e6ba84e".to_string(), sha512: "471babff84b36bd0f5051051bc192a97136ba733df6a49f222cb67a231d857eb4b1c5ec8dea605e146f49f75f800709f8836540a472fe8032f9fbd3f6690ec3d".to_string() },
                env: Some(Env {
                    client: SideSupport::Optional,
                    server: SideSupport::Optional,
                }),
                downloads: vec!["https://cdn.modrinth.com/data/P7dR8mSH/versions/X2hTodix/fabric-api-0.129.0%2B1.21.8.jar".to_string()],
                file_size: 2_212_412,
            },
            dependencies: vec![],
            project_id: "P7dR8mSH".to_string(),
        }, file);
    }
}