Switch to time crate, add file sizes (#329)

* Switch to time crate, add file sizes

* Update deps, adjust pack format

* Run formatter, fix clippy
This commit is contained in:
Geometrically
2022-03-29 19:35:09 -07:00
committed by GitHub
parent a3d5479878
commit 80e00a80d5
38 changed files with 563 additions and 318 deletions

View File

@@ -1,8 +1,8 @@
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use chrono::{DateTime, NaiveDateTime, Utc};
use std::io::Cursor;
use time::OffsetDateTime;
use zip::ZipArchive;
pub struct FabricValidator;
@@ -22,9 +22,8 @@ impl super::Validator for FabricValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 18w49a, the first fabric version
SupportedGameVersions::PastDate(DateTime::from_utc(
NaiveDateTime::from_timestamp(1543969469, 0),
Utc,
SupportedGameVersions::PastDate(OffsetDateTime::from_unix_timestamp(
1543969469,
))
}

View File

@@ -1,8 +1,8 @@
use crate::validate::{
SupportedGameVersions, ValidationError, ValidationResult,
};
use chrono::{DateTime, NaiveDateTime, Utc};
use std::io::Cursor;
use time::OffsetDateTime;
use zip::ZipArchive;
pub struct ForgeValidator;
@@ -22,9 +22,8 @@ impl super::Validator for ForgeValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Time since release of 1.13, the first forge version which uses the new TOML system
SupportedGameVersions::PastDate(DateTime::<Utc>::from_utc(
NaiveDateTime::from_timestamp(1540122067, 0),
Utc,
SupportedGameVersions::PastDate(OffsetDateTime::from_unix_timestamp(
1540122067,
))
}
@@ -68,14 +67,8 @@ impl super::Validator for LegacyForgeValidator {
fn get_supported_game_versions(&self) -> SupportedGameVersions {
// Times between versions 1.5.2 to 1.12.2, which all use the legacy way of defining mods
SupportedGameVersions::Range(
DateTime::from_utc(
NaiveDateTime::from_timestamp(1366818300, 0),
Utc,
),
DateTime::from_utc(
NaiveDateTime::from_timestamp(1505810340, 0),
Utc,
),
OffsetDateTime::from_unix_timestamp(1366818300),
OffsetDateTime::from_unix_timestamp(1505810340),
)
}

View File

@@ -2,9 +2,9 @@ use crate::models::projects::{GameVersion, Loader};
use crate::validate::fabric::FabricValidator;
use crate::validate::forge::{ForgeValidator, LegacyForgeValidator};
use crate::validate::pack::PackValidator;
use chrono::{DateTime, Utc};
use std::io::Cursor;
use thiserror::Error;
use time::OffsetDateTime;
use zip::ZipArchive;
mod fabric;
@@ -35,8 +35,8 @@ pub enum ValidationResult {
pub enum SupportedGameVersions {
All,
PastDate(DateTime<Utc>),
Range(DateTime<Utc>, DateTime<Utc>),
PastDate(OffsetDateTime),
Range(OffsetDateTime, OffsetDateTime),
#[allow(dead_code)]
Custom(Vec<GameVersion>),
}

View File

@@ -33,6 +33,7 @@ pub struct PackFile<'a> {
pub env: Option<std::collections::HashMap<EnvType, SideType>>,
#[validate(custom(function = "validate_download_url"))]
pub downloads: Vec<&'a str>,
pub file_size: u32,
}
fn validate_download_url(
@@ -167,6 +168,12 @@ impl super::Validator for PackValidator {
));
}
if file.hashes.get(&FileHash::Sha512).is_none() {
return Err(ValidationError::InvalidInput(
"All pack files must provide a SHA512 hash!".into(),
));
}
let path = std::path::Path::new(file.path)
.components()
.next()