You've already forked AstralRinth
forked from didirus/AstralRinth
Fix validators (#237)
* Fix file extension checks not working * Fix validators not validating files of a non-matching extension
This commit is contained in:
@@ -535,7 +535,7 @@ pub async fn project_create_inner(
|
|||||||
let mut categories = Vec::with_capacity(project_create_data.categories.len());
|
let mut categories = Vec::with_capacity(project_create_data.categories.len());
|
||||||
for category in &project_create_data.categories {
|
for category in &project_create_data.categories {
|
||||||
let id = models::categories::Category::get_id_project(
|
let id = models::categories::Category::get_id_project(
|
||||||
&category,
|
category,
|
||||||
project_type_id,
|
project_type_id,
|
||||||
&mut *transaction,
|
&mut *transaction,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ pub fn validate_file(
|
|||||||
let reader = std::io::Cursor::new(data);
|
let reader = std::io::Cursor::new(data);
|
||||||
let mut zip = zip::ZipArchive::new(reader)?;
|
let mut zip = zip::ZipArchive::new(reader)?;
|
||||||
|
|
||||||
|
let mut visited = false;
|
||||||
for validator in &VALIDATORS {
|
for validator in &VALIDATORS {
|
||||||
if validator.get_file_extensions().contains(&file_extension)
|
if
|
||||||
&& validator.get_project_types().contains(&project_type)
|
validator.get_project_types().contains(&project_type)
|
||||||
&& loaders
|
&& loaders
|
||||||
.iter()
|
.iter()
|
||||||
.any(|x| validator.get_supported_loaders().contains(&&*x.0))
|
.any(|x| validator.get_supported_loaders().contains(&&*x.0))
|
||||||
@@ -80,11 +81,19 @@ pub fn validate_file(
|
|||||||
validator.get_supported_game_versions(),
|
validator.get_supported_game_versions(),
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return validator.validate(&mut zip);
|
if validator.get_file_extensions().contains(&file_extension) {
|
||||||
|
return validator.validate(&mut zip);
|
||||||
|
} else {
|
||||||
|
visited = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ValidationResult::Pass)
|
if visited {
|
||||||
|
Err(ValidationError::InvalidInputError(format!("File extension {} is invalid for input file", file_extension)))
|
||||||
|
} else {
|
||||||
|
Ok(ValidationResult::Pass)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn game_version_supported(
|
fn game_version_supported(
|
||||||
|
|||||||
Reference in New Issue
Block a user