From 69928219a3c6879a5556dd3ee990eebf823f5904 Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Wed, 25 Aug 2021 23:18:44 -0700 Subject: [PATCH] Fix project creation hash lookups failing (#239) --- src/routes/version_creation.rs | 4 +--- src/routes/versions.rs | 1 - src/validate/mod.rs | 8 +++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/routes/version_creation.rs b/src/routes/version_creation.rs index 472bdd098..ae53b1a0a 100644 --- a/src/routes/version_creation.rs +++ b/src/routes/version_creation.rs @@ -586,7 +586,6 @@ pub async fn upload_file( .ok_or_else(|| CreateError::InvalidFileType(file_extension.to_string()))?; let mut data = Vec::new(); - let mut hash = sha1::Sha1::new(); while let Some(chunk) = field.next().await { // Project file size limit of 100MiB const FILE_SIZE_CAP: usize = 100 * (1 << 20); @@ -597,12 +596,11 @@ pub async fn upload_file( )); } else { let bytes = chunk.map_err(CreateError::MultipartError)?; - hash.update(&data); data.append(&mut bytes.to_vec()); } } - let hash = hash.digest().to_string(); + let hash = sha1::Sha1::from(&data).hexdigest(); let exists = sqlx::query!( " SELECT EXISTS(SELECT 1 FROM hashes h diff --git a/src/routes/versions.rs b/src/routes/versions.rs index d43c0dfcd..e9ef5dcd0 100644 --- a/src/routes/versions.rs +++ b/src/routes/versions.rs @@ -220,7 +220,6 @@ pub struct EditVersion { #[validate(length(max = 65536))] pub changelog: Option, pub version_type: Option, - #[validate(length(min = 1, max = 256))] pub dependencies: Option>, pub game_versions: Option>, pub loaders: Option>, diff --git a/src/validate/mod.rs b/src/validate/mod.rs index 3eae2c983..6322859b6 100644 --- a/src/validate/mod.rs +++ b/src/validate/mod.rs @@ -70,8 +70,7 @@ pub fn validate_file( let mut visited = false; for validator in &VALIDATORS { - if - validator.get_project_types().contains(&project_type) + if validator.get_project_types().contains(&project_type) && loaders .iter() .any(|x| validator.get_supported_loaders().contains(&&*x.0)) @@ -90,7 +89,10 @@ pub fn validate_file( } if visited { - Err(ValidationError::InvalidInputError(format!("File extension {} is invalid for input file", file_extension))) + Err(ValidationError::InvalidInputError(format!( + "File extension {} is invalid for input file", + file_extension + ))) } else { Ok(ValidationResult::Pass) }