Upgrade to Actix V2, bump SQLX version, code cleanup, intergrate ratelimiter (#288)

* Upgrade to Actix V2, bump SQLX version, code cleanup, intergrate ratelimiter

* Add pack file path validation

* Fix compilation error caused by incorrect merge
This commit is contained in:
Geometrically
2022-02-05 23:08:30 -07:00
committed by GitHub
parent 6a89646e66
commit 6bf5dbabee
27 changed files with 1417 additions and 1649 deletions

View File

@@ -22,7 +22,7 @@ pub enum ValidationError {
#[error("Invalid Input: {0}")]
InvalidInputError(std::borrow::Cow<'static, str>),
#[error("Error while managing threads")]
BlockingError,
BlockingError(#[from] actix_web::error::BlockingError),
}
#[derive(Eq, PartialEq)]
@@ -67,7 +67,7 @@ pub async fn validate_file(
game_versions: Vec<GameVersion>,
all_game_versions: Vec<crate::database::models::categories::GameVersion>,
) -> Result<ValidationResult, ValidationError> {
let res = actix_web::web::block(move || {
actix_web::web::block(move || {
let reader = std::io::Cursor::new(data);
let mut zip = zip::ZipArchive::new(reader)?;
@@ -103,15 +103,7 @@ pub async fn validate_file(
Ok(ValidationResult::Pass)
}
})
.await;
match res {
Ok(x) => Ok(x),
Err(err) => match err {
actix_web::error::BlockingError::Canceled => Err(ValidationError::BlockingError),
actix_web::error::BlockingError::Error(err) => Err(err),
},
}
.await?
}
fn game_version_supported(

View File

@@ -4,6 +4,7 @@ use crate::util::validate::validation_errors_to_string;
use crate::validate::{SupportedGameVersions, ValidationError, ValidationResult};
use serde::{Deserialize, Serialize};
use std::io::{Cursor, Read};
use std::path::Component;
use validator::Validate;
use zip::ZipArchive;
@@ -155,6 +156,22 @@ impl super::Validator for PackValidator {
"All pack files must provide a SHA1 hash!".into(),
));
}
let path = std::path::Path::new(file.path)
.components()
.next()
.ok_or_else(|| {
ValidationError::InvalidInputError("Invalid pack file path!".into())
})?;
match path {
Component::CurDir | Component::Normal(_) => {}
_ => {
return Err(ValidationError::InvalidInputError(
"Invalid pack file path!".into(),
))
}
};
}
Ok(ValidationResult::Pass)