You've already forked AstralRinth
forked from didirus/AstralRinth
Run fmt, fix dep route (#312)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
};
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use std::io::Cursor;
|
||||
use zip::ZipArchive;
|
||||
@@ -31,13 +33,14 @@ impl super::Validator for FabricValidator {
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("fabric.mod.json").map_err(|_| {
|
||||
ValidationError::InvalidInputError("No fabric.mod.json present for Fabric file.".into())
|
||||
ValidationError::InvalidInputError(
|
||||
"No fabric.mod.json present for Fabric file.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !archive
|
||||
.file_names()
|
||||
.any(|name| name.ends_with("refmap.json") || name.ends_with(".class"))
|
||||
{
|
||||
if !archive.file_names().any(|name| {
|
||||
name.ends_with("refmap.json") || name.ends_with(".class")
|
||||
}) {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"Fabric mod file is a source file!",
|
||||
));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
};
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use std::io::Cursor;
|
||||
use zip::ZipArchive;
|
||||
@@ -31,7 +33,9 @@ impl super::Validator for ForgeValidator {
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("META-INF/mods.toml").map_err(|_| {
|
||||
ValidationError::InvalidInputError("No mods.toml present for Forge file.".into())
|
||||
ValidationError::InvalidInputError(
|
||||
"No mods.toml present for Forge file.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !archive.file_names().any(|name| name.ends_with(".class")) {
|
||||
@@ -64,8 +68,14 @@ 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),
|
||||
DateTime::from_utc(
|
||||
NaiveDateTime::from_timestamp(1366818300, 0),
|
||||
Utc,
|
||||
),
|
||||
DateTime::from_utc(
|
||||
NaiveDateTime::from_timestamp(1505810340, 0),
|
||||
Utc,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -74,7 +84,9 @@ impl super::Validator for LegacyForgeValidator {
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("mcmod.info").map_err(|_| {
|
||||
ValidationError::InvalidInputError("No mcmod.info present for Forge file.".into())
|
||||
ValidationError::InvalidInputError(
|
||||
"No mcmod.info present for Forge file.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if !archive.file_names().any(|name| name.ends_with(".class")) {
|
||||
|
||||
@@ -114,20 +114,24 @@ fn game_version_supported(
|
||||
) -> bool {
|
||||
match supported_game_versions {
|
||||
SupportedGameVersions::All => true,
|
||||
SupportedGameVersions::PastDate(date) => game_versions.iter().any(|x| {
|
||||
all_game_versions
|
||||
.iter()
|
||||
.find(|y| y.version == x.0)
|
||||
.map(|x| x.date > date)
|
||||
.unwrap_or(false)
|
||||
}),
|
||||
SupportedGameVersions::Range(before, after) => game_versions.iter().any(|x| {
|
||||
all_game_versions
|
||||
.iter()
|
||||
.find(|y| y.version == x.0)
|
||||
.map(|x| x.date > before && x.date < after)
|
||||
.unwrap_or(false)
|
||||
}),
|
||||
SupportedGameVersions::PastDate(date) => {
|
||||
game_versions.iter().any(|x| {
|
||||
all_game_versions
|
||||
.iter()
|
||||
.find(|y| y.version == x.0)
|
||||
.map(|x| x.date > date)
|
||||
.unwrap_or(false)
|
||||
})
|
||||
}
|
||||
SupportedGameVersions::Range(before, after) => {
|
||||
game_versions.iter().any(|x| {
|
||||
all_game_versions
|
||||
.iter()
|
||||
.find(|y| y.version == x.0)
|
||||
.map(|x| x.date > before && x.date < after)
|
||||
.unwrap_or(false)
|
||||
})
|
||||
}
|
||||
SupportedGameVersions::Custom(versions) => {
|
||||
versions.iter().any(|x| game_versions.contains(x))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::models::projects::SideType;
|
||||
use crate::util::env::parse_strings_from_var;
|
||||
use crate::util::validate::validation_errors_to_string;
|
||||
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::{Cursor, Read};
|
||||
use std::path::Component;
|
||||
@@ -33,7 +35,9 @@ pub struct PackFile<'a> {
|
||||
pub downloads: Vec<&'a str>,
|
||||
}
|
||||
|
||||
fn validate_download_url(values: &[&str]) -> Result<(), validator::ValidationError> {
|
||||
fn validate_download_url(
|
||||
values: &[&str],
|
||||
) -> Result<(), validator::ValidationError> {
|
||||
for value in values {
|
||||
let url = url::Url::parse(value)
|
||||
.ok()
|
||||
@@ -43,7 +47,8 @@ fn validate_download_url(values: &[&str]) -> Result<(), validator::ValidationErr
|
||||
return Err(validator::ValidationError::new("invalid URL"));
|
||||
}
|
||||
|
||||
let domains = parse_strings_from_var("WHITELISTED_MODPACK_DOMAINS").unwrap_or_default();
|
||||
let domains = parse_strings_from_var("WHITELISTED_MODPACK_DOMAINS")
|
||||
.unwrap_or_default();
|
||||
if !domains.contains(
|
||||
&url.domain()
|
||||
.ok_or_else(|| validator::ValidationError::new("invalid URL"))?
|
||||
@@ -131,9 +136,12 @@ impl super::Validator for PackValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
let mut file = archive
|
||||
.by_name("modrinth.index.json")
|
||||
.map_err(|_| ValidationError::InvalidInputError("Pack manifest is missing.".into()))?;
|
||||
let mut file =
|
||||
archive.by_name("modrinth.index.json").map_err(|_| {
|
||||
ValidationError::InvalidInputError(
|
||||
"Pack manifest is missing.".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
@@ -141,7 +149,9 @@ impl super::Validator for PackValidator {
|
||||
let pack: PackFormat = serde_json::from_str(&contents)?;
|
||||
|
||||
pack.validate().map_err(|err| {
|
||||
ValidationError::InvalidInputError(validation_errors_to_string(err, None).into())
|
||||
ValidationError::InvalidInputError(
|
||||
validation_errors_to_string(err, None).into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
if pack.game != "minecraft" {
|
||||
@@ -161,7 +171,9 @@ impl super::Validator for PackValidator {
|
||||
.components()
|
||||
.next()
|
||||
.ok_or_else(|| {
|
||||
ValidationError::InvalidInputError("Invalid pack file path!".into())
|
||||
ValidationError::InvalidInputError(
|
||||
"Invalid pack file path!".into(),
|
||||
)
|
||||
})?;
|
||||
|
||||
match path {
|
||||
|
||||
Reference in New Issue
Block a user