Add even more validators (#385)
* Add even more validators I was gonna add shaderpacks too, but those have no standard metadata file at all. * Make it compile * Fix logic * Update validators * fix mistake Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
parent
68f7dc9512
commit
02c3894fc9
@ -3,10 +3,10 @@ use crate::models::projects::{GameVersion, Loader};
|
|||||||
use crate::validate::fabric::FabricValidator;
|
use crate::validate::fabric::FabricValidator;
|
||||||
use crate::validate::forge::{ForgeValidator, LegacyForgeValidator};
|
use crate::validate::forge::{ForgeValidator, LegacyForgeValidator};
|
||||||
use crate::validate::liteloader::LiteLoaderValidator;
|
use crate::validate::liteloader::LiteLoaderValidator;
|
||||||
use crate::validate::pack::PackValidator;
|
use crate::validate::modpack::ModpackValidator;
|
||||||
use crate::validate::plugin::PluginValidator;
|
use crate::validate::plugin::*;
|
||||||
use crate::validate::quilt::QuiltValidator;
|
use crate::validate::quilt::QuiltValidator;
|
||||||
use crate::validate::resourcepack::ResourcePackValidator;
|
use crate::validate::resourcepack::{PackValidator, TexturePackValidator};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
@ -15,7 +15,7 @@ use zip::ZipArchive;
|
|||||||
mod fabric;
|
mod fabric;
|
||||||
mod forge;
|
mod forge;
|
||||||
mod liteloader;
|
mod liteloader;
|
||||||
mod pack;
|
mod modpack;
|
||||||
mod plugin;
|
mod plugin;
|
||||||
mod quilt;
|
mod quilt;
|
||||||
mod resourcepack;
|
mod resourcepack;
|
||||||
@ -76,15 +76,19 @@ pub trait Validator: Sync {
|
|||||||
) -> Result<ValidationResult, ValidationError>;
|
) -> Result<ValidationResult, ValidationError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALIDATORS: [&dyn Validator; 8] = [
|
static VALIDATORS: [&dyn Validator; 12] = [
|
||||||
&PackValidator,
|
&ModpackValidator,
|
||||||
&FabricValidator,
|
&FabricValidator,
|
||||||
&ForgeValidator,
|
&ForgeValidator,
|
||||||
&LegacyForgeValidator,
|
&LegacyForgeValidator,
|
||||||
&QuiltValidator,
|
&QuiltValidator,
|
||||||
&LiteLoaderValidator,
|
&LiteLoaderValidator,
|
||||||
&ResourcePackValidator,
|
&PackValidator,
|
||||||
&PluginValidator,
|
&TexturePackValidator,
|
||||||
|
&BukkitValidator,
|
||||||
|
&BungeeCordValidator,
|
||||||
|
&VelocityValidator,
|
||||||
|
&SpongeValidator,
|
||||||
];
|
];
|
||||||
|
|
||||||
/// The return value is whether this file should be marked as primary or not, based on the analysis of the file
|
/// The return value is whether this file should be marked as primary or not, based on the analysis of the file
|
||||||
@ -97,8 +101,8 @@ pub async fn validate_file(
|
|||||||
all_game_versions: Vec<crate::database::models::categories::GameVersion>,
|
all_game_versions: Vec<crate::database::models::categories::GameVersion>,
|
||||||
) -> Result<ValidationResult, ValidationError> {
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
actix_web::web::block(move || {
|
actix_web::web::block(move || {
|
||||||
let reader = std::io::Cursor::new(data);
|
let reader = Cursor::new(data);
|
||||||
let mut zip = zip::ZipArchive::new(reader)?;
|
let mut zip = ZipArchive::new(reader)?;
|
||||||
|
|
||||||
let mut visited = false;
|
let mut visited = false;
|
||||||
for validator in &VALIDATORS {
|
for validator in &VALIDATORS {
|
||||||
|
|||||||
@ -8,9 +8,9 @@ use std::path::Component;
|
|||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
pub struct PackValidator;
|
pub struct ModpackValidator;
|
||||||
|
|
||||||
impl super::Validator for PackValidator {
|
impl super::Validator for ModpackValidator {
|
||||||
fn get_file_extensions(&self) -> &[&str] {
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
&["mrpack"]
|
&["mrpack"]
|
||||||
}
|
}
|
||||||
@ -4,9 +4,9 @@ use crate::validate::{
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
pub struct PluginValidator;
|
pub struct BukkitValidator;
|
||||||
|
|
||||||
impl super::Validator for PluginValidator {
|
impl super::Validator for BukkitValidator {
|
||||||
fn get_file_extensions(&self) -> &[&str] {
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
&["zip", "jar"]
|
&["zip", "jar"]
|
||||||
}
|
}
|
||||||
@ -36,3 +36,105 @@ impl super::Validator for PluginValidator {
|
|||||||
Ok(ValidationResult::Pass)
|
Ok(ValidationResult::Pass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct BungeeCordValidator;
|
||||||
|
|
||||||
|
impl super::Validator for BungeeCordValidator {
|
||||||
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
|
&["zip", "jar"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_project_types(&self) -> &[&str] {
|
||||||
|
&["mod"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_loaders(&self) -> &[&str] {
|
||||||
|
&["bungeecord", "waterfall"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||||
|
SupportedGameVersions::All
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(
|
||||||
|
&self,
|
||||||
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||||
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
|
archive.by_name("bungee.yml").map_err(|_| {
|
||||||
|
ValidationError::InvalidInput(
|
||||||
|
"No bungee.yml present for plugin file.".into(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(ValidationResult::Pass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct VelocityValidator;
|
||||||
|
|
||||||
|
impl super::Validator for VelocityValidator {
|
||||||
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
|
&["zip", "jar"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_project_types(&self) -> &[&str] {
|
||||||
|
&["mod"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_loaders(&self) -> &[&str] {
|
||||||
|
&["velocity"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||||
|
SupportedGameVersions::All
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(
|
||||||
|
&self,
|
||||||
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||||
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
|
archive.by_name("velocity-plugin.json").map_err(|_| {
|
||||||
|
ValidationError::InvalidInput(
|
||||||
|
"No velocity-plugin.json present for plugin file.".into(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(ValidationResult::Pass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SpongeValidator;
|
||||||
|
|
||||||
|
impl super::Validator for SpongeValidator {
|
||||||
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
|
&["zip", "jar"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_project_types(&self) -> &[&str] {
|
||||||
|
&["mod"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_loaders(&self) -> &[&str] {
|
||||||
|
&["sponge"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||||
|
SupportedGameVersions::All
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(
|
||||||
|
&self,
|
||||||
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||||
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
|
if !archive
|
||||||
|
.file_names()
|
||||||
|
.any(|name| name == "sponge_plugins.json" || name == "mcmod.info")
|
||||||
|
{
|
||||||
|
return Ok(ValidationResult::Warning(
|
||||||
|
"No sponge_plugins.json or mcmod.info present for Sponge plugin.",
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(ValidationResult::Pass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ impl super::Validator for QuiltValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_supported_loaders(&self) -> &[&str] {
|
fn get_supported_loaders(&self) -> &[&str] {
|
||||||
&["fabric"]
|
&["quilt"]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||||
|
|||||||
@ -2,11 +2,48 @@ use crate::validate::{
|
|||||||
SupportedGameVersions, ValidationError, ValidationResult,
|
SupportedGameVersions, ValidationError, ValidationResult,
|
||||||
};
|
};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
use time::OffsetDateTime;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
pub struct ResourcePackValidator;
|
pub struct PackValidator;
|
||||||
|
|
||||||
impl super::Validator for ResourcePackValidator {
|
impl super::Validator for PackValidator {
|
||||||
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
|
&["zip"]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_project_types(&self) -> &[&str] {
|
||||||
|
&["resourcepack", "datapack"]
|
||||||
|
}
|
||||||
|
|
||||||
|
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(OffsetDateTime::from_unix_timestamp(
|
||||||
|
1371137542,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate(
|
||||||
|
&self,
|
||||||
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||||
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
|
archive.by_name("pack.mcmeta").map_err(|_| {
|
||||||
|
ValidationError::InvalidInput(
|
||||||
|
"No pack.mcmeta present for pack file.".into(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(ValidationResult::Pass)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TexturePackValidator;
|
||||||
|
|
||||||
|
impl super::Validator for TexturePackValidator {
|
||||||
fn get_file_extensions(&self) -> &[&str] {
|
fn get_file_extensions(&self) -> &[&str] {
|
||||||
&["zip"]
|
&["zip"]
|
||||||
}
|
}
|
||||||
@ -20,16 +57,20 @@ impl super::Validator for ResourcePackValidator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||||
SupportedGameVersions::All
|
// a1.2.2a to 13w23b
|
||||||
|
SupportedGameVersions::Range(
|
||||||
|
OffsetDateTime::from_unix_timestamp(1289339999),
|
||||||
|
OffsetDateTime::from_unix_timestamp(1370651522),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate(
|
fn validate(
|
||||||
&self,
|
&self,
|
||||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||||
) -> Result<ValidationResult, ValidationError> {
|
) -> Result<ValidationResult, ValidationError> {
|
||||||
archive.by_name("pack.mcmeta").map_err(|_| {
|
archive.by_name("pack.txt").map_err(|_| {
|
||||||
ValidationError::InvalidInput(
|
ValidationError::InvalidInput(
|
||||||
"No pack.mcmeta present for resourcepack file.".into(),
|
"No pack.txt present for pack file.".into(),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user