Files
AstralRinth/src/validate/forge.rs
Geometrically 07ecd13554 Switch to Trolley for Modrinth Payments (#727)
* most of trolley

* Switch to trolley for payments

* run prepare

* fix clippy

* fix more

* Fix most tests + bitflags

* Update src/auth/flows.rs

Co-authored-by: Jackson Kruger <jak.kruger@gmail.com>

* Finish trolley

* run prep for merge

* Update src/queue/payouts.rs

Co-authored-by: Jackson Kruger <jak.kruger@gmail.com>

---------

Co-authored-by: Jackson Kruger <jak.kruger@gmail.com>
2023-10-11 15:55:01 -07:00

87 lines
2.4 KiB
Rust

use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use chrono::{DateTime, NaiveDateTime, Utc};
use std::io::Cursor;
use zip::ZipArchive;
pub struct ForgeValidator;
impl super::Validator for ForgeValidator {
fn get_file_extensions(&self) -> &[&str] {
&["jar", "zip"]
}
fn get_project_types(&self) -> &[&str] {
&["mod"]
}
fn get_supported_loaders(&self) -> &[&str] {
&["forge"]
}
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_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1540122067, 0).unwrap(),
Utc,
))
}
fn validate(
&self,
_archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
// if archive.by_name("META-INF/mods.toml").is_err() {
// return Ok(ValidationResult::Warning(
// "No mods.toml present for Forge file.",
// ));
// }
Ok(ValidationResult::Pass)
}
}
pub struct LegacyForgeValidator;
impl super::Validator for LegacyForgeValidator {
fn get_file_extensions(&self) -> &[&str] {
&["jar", "zip"]
}
fn get_project_types(&self) -> &[&str] {
&["mod"]
}
fn get_supported_loaders(&self) -> &[&str] {
&["forge"]
}
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_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1366818300, 0).unwrap(),
Utc,
),
DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(1505810340, 0).unwrap(),
Utc,
),
)
}
fn validate(
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
if archive.by_name("mcmod.info").is_err() {
return Ok(ValidationResult::Warning(
"Forge mod file does not contain mcmod.info!",
));
};
//TODO: Check if file is a dev JAR?
Ok(ValidationResult::Pass)
}
}