You've already forked pages
forked from didirus/AstralRinth
* fix(labrinth): return version artifact size exceeded error eagerly Now we don't wait until the result memory buffer has grown to a size greater than the maximum allowed, and instead we return such an error before the buffer is grown with the current chunk, which should reduce memory usage. * fix(labrinth): proper supported game versions range for datapacks * feat(labrinth): allow protected resource and data packs to pass validation
80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use crate::validate::{
|
|
MaybeProtectedZipFile, PLAUSIBLE_PACK_REGEX, SupportedGameVersions,
|
|
ValidationError, ValidationResult,
|
|
};
|
|
use chrono::DateTime;
|
|
use std::io::Cursor;
|
|
use zip::ZipArchive;
|
|
|
|
pub struct PackValidator;
|
|
|
|
impl super::Validator for PackValidator {
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
&["zip"]
|
|
}
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
&["minecraft"]
|
|
}
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
// Time since release of 13w24a which replaced texture packs with resource packs
|
|
SupportedGameVersions::PastDate(
|
|
DateTime::from_timestamp(1371137542, 0).unwrap(),
|
|
)
|
|
}
|
|
|
|
fn validate_maybe_protected_zip(
|
|
&self,
|
|
file: &mut MaybeProtectedZipFile,
|
|
) -> Result<ValidationResult, ValidationError> {
|
|
if match file {
|
|
MaybeProtectedZipFile::Unprotected(archive) => {
|
|
archive.by_name("pack.mcmeta").is_ok()
|
|
}
|
|
MaybeProtectedZipFile::MaybeProtected { data, .. } => {
|
|
PLAUSIBLE_PACK_REGEX.is_match(data)
|
|
}
|
|
} {
|
|
Ok(ValidationResult::Pass)
|
|
} else {
|
|
Ok(ValidationResult::Warning(
|
|
"No pack.mcmeta present for resourcepack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
|
))
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct TexturePackValidator;
|
|
|
|
impl super::Validator for TexturePackValidator {
|
|
fn get_file_extensions(&self) -> &[&str] {
|
|
&["zip"]
|
|
}
|
|
|
|
fn get_supported_loaders(&self) -> &[&str] {
|
|
&["minecraft"]
|
|
}
|
|
|
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
|
// a1.2.2a to 13w23b
|
|
SupportedGameVersions::Range(
|
|
DateTime::from_timestamp(1289339999, 0).unwrap(),
|
|
DateTime::from_timestamp(1370651522, 0).unwrap(),
|
|
)
|
|
}
|
|
|
|
fn validate(
|
|
&self,
|
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
|
) -> Result<ValidationResult, ValidationError> {
|
|
if archive.by_name("pack.txt").is_err() {
|
|
return Ok(ValidationResult::Warning(
|
|
"No pack.txt present for pack file.",
|
|
));
|
|
}
|
|
|
|
Ok(ValidationResult::Pass)
|
|
}
|
|
}
|