You've already forked AstralRinth
forked from didirus/AstralRinth
Monetization status, additional files fix, deps fix (#574)
This commit is contained in:
@@ -27,11 +27,11 @@ impl super::Validator for DataPackValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("pack.mcmeta").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No pack.mcmeta present for datapack file. Tip: Make sure pack.mcmeta is in the root directory of your datapack!".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("pack.mcmeta").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta present for datapack file. Tip: Make sure pack.mcmeta is in the root directory of your datapack!",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
|
||||
@@ -32,11 +32,11 @@ impl super::Validator for FabricValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("fabric.mod.json").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No fabric.mod.json present for Fabric file.".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("fabric.mod.json").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No fabric.mod.json present for Fabric file.",
|
||||
));
|
||||
}
|
||||
|
||||
if !archive.file_names().any(|name| {
|
||||
name.ends_with("refmap.json") || name.ends_with(".class")
|
||||
|
||||
@@ -27,11 +27,11 @@ impl super::Validator for LiteLoaderValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("litemod.json").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No litemod.json present for LiteLoader file.".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("litemod.json").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No litemod.json present for LiteLoader file.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,9 @@ pub trait Validator: Sync {
|
||||
) -> Result<ValidationResult, ValidationError>;
|
||||
}
|
||||
|
||||
static VALIDATORS: [&dyn Validator; 16] = [
|
||||
static ALWAYS_ALLOWED_EXT: &[&str] = &["zip", "txt"];
|
||||
|
||||
static VALIDATORS: &[&dyn Validator] = &[
|
||||
&ModpackValidator,
|
||||
&FabricValidator,
|
||||
&ForgeValidator,
|
||||
@@ -127,7 +129,7 @@ pub async fn validate_file(
|
||||
}
|
||||
|
||||
let mut visited = false;
|
||||
for validator in &VALIDATORS {
|
||||
for validator in VALIDATORS {
|
||||
if validator.get_project_types().contains(&&*project_type)
|
||||
&& loaders
|
||||
.iter()
|
||||
@@ -147,12 +149,16 @@ pub async fn validate_file(
|
||||
}
|
||||
|
||||
if visited {
|
||||
Err(ValidationError::InvalidInput(
|
||||
format!(
|
||||
"File extension {file_extension} is invalid for input file"
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
if ALWAYS_ALLOWED_EXT.contains(&&*file_extension) {
|
||||
Ok(ValidationResult::Warning("File extension is invalid for input file"))
|
||||
} else {
|
||||
Err(ValidationError::InvalidInput(
|
||||
format!(
|
||||
"File extension {file_extension} is invalid for input file"
|
||||
)
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
} else {
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
|
||||
@@ -33,11 +33,13 @@ impl super::Validator for ModpackValidator {
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
let pack: PackFormat = {
|
||||
let mut file =
|
||||
archive.by_name("modrinth.index.json").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"Pack manifest is missing.".into(),
|
||||
)
|
||||
})?;
|
||||
if let Ok(file) = archive.by_name("modrinth.index.json") {
|
||||
file
|
||||
} else {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"Pack manifest is missing.",
|
||||
));
|
||||
};
|
||||
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
|
||||
@@ -67,11 +67,11 @@ impl super::Validator for BungeeCordValidator {
|
||||
&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(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("bungee.yml").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No bungee.yml present for plugin file.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ impl super::Validator for QuiltValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("quilt.mod.json").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No quilt.mod.json present for Quilt file.".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("quilt.mod.json").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No quilt.mod.json present for Quilt file.",
|
||||
));
|
||||
}
|
||||
|
||||
if !archive.file_names().any(|name| {
|
||||
name.ends_with("refmap.json") || name.ends_with(".class")
|
||||
|
||||
@@ -32,11 +32,11 @@ impl super::Validator for PackValidator {
|
||||
&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. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("pack.mcmeta").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
@@ -75,11 +75,11 @@ impl super::Validator for TexturePackValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("pack.txt").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No pack.txt present for pack file.".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("pack.txt").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.txt present for pack file.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ impl super::Validator for ShaderValidator {
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
if !archive.file_names().any(|x| x.starts_with("shaders/")) {
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No shaders folder present for OptiFine/Iris shader.".into(),
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No shaders folder present for OptiFine/Iris shader.",
|
||||
));
|
||||
}
|
||||
|
||||
@@ -60,15 +60,15 @@ impl super::Validator for CanvasShaderValidator {
|
||||
&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. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("pack.mcmeta").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
||||
));
|
||||
};
|
||||
|
||||
if !archive.file_names().any(|x| x.contains("/pipelines/")) {
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No pipeline shaders folder present for canvas shaders.".into(),
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pipeline shaders folder present for canvas shaders.",
|
||||
));
|
||||
}
|
||||
|
||||
@@ -99,18 +99,18 @@ impl super::Validator for CoreShaderValidator {
|
||||
&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. Tip: Make sure pack.mcmeta is in the root directory of your pack!".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("pack.mcmeta").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
||||
));
|
||||
};
|
||||
|
||||
if !archive
|
||||
.file_names()
|
||||
.any(|x| x.starts_with("assets/minecraft/shaders/"))
|
||||
{
|
||||
return Err(ValidationError::InvalidInput(
|
||||
"No shaders folder present for vanilla shaders.".into(),
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No shaders folder present for vanilla shaders.",
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user