You've already forked AstralRinth
forked from didirus/AstralRinth
Add quilt validators, Deps fix, Fix slug collisions (#338)
This commit is contained in:
@@ -201,10 +201,10 @@ impl VersionBuilder {
|
||||
let dependencies = sqlx::query!(
|
||||
"
|
||||
SELECT d.id id
|
||||
FROM versions v
|
||||
INNER JOIN dependencies d ON d.mod_dependency_id = $1
|
||||
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id = ANY($2)
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id = ANY($3)
|
||||
FROM dependencies d
|
||||
INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = d.dependent_id AND gvv.game_version_id = ANY($2)
|
||||
INNER JOIN loaders_versions lv ON lv.version_id = d.dependent_id AND lv.loader_id = ANY($3)
|
||||
WHERE d.mod_dependency_id = $1
|
||||
",
|
||||
self.project_id as ProjectId,
|
||||
&self.game_versions.iter().map(|x| x.0).collect::<Vec<i32>>(),
|
||||
|
||||
@@ -373,7 +373,23 @@ pub async fn project_create_inner(
|
||||
.await
|
||||
.map_err(|e| CreateError::DatabaseError(e.into()))?;
|
||||
|
||||
if results.exists.unwrap_or(true) {
|
||||
if results.exists.unwrap_or(false) {
|
||||
return Err(CreateError::SlugCollision);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let results = sqlx::query!(
|
||||
"
|
||||
SELECT EXISTS(SELECT 1 FROM mods WHERE slug = $1)
|
||||
",
|
||||
create_data.slug
|
||||
)
|
||||
.fetch_one(&mut *transaction)
|
||||
.await
|
||||
.map_err(|e| CreateError::DatabaseError(e.into()))?;
|
||||
|
||||
if results.exists.unwrap_or(false) {
|
||||
return Err(CreateError::SlugCollision);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,6 @@ pub async fn search_for_project(
|
||||
filter_string.push_str(&*filters);
|
||||
}
|
||||
|
||||
println!("{}", filter_string);
|
||||
if !filter_string.is_empty() {
|
||||
query.with_filter(&filter_string);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,6 @@ impl super::Validator for FabricValidator {
|
||||
));
|
||||
}
|
||||
|
||||
//TODO: Check if file is a dev JAR?
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ impl super::Validator for ForgeValidator {
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
archive.by_name("META-INF/mods.toml").map_err(|_| {
|
||||
ValidationError::InvalidInput(
|
||||
"No mods.toml present for Forge file.".into(),
|
||||
)
|
||||
})?;
|
||||
if archive.by_name("META-INF/mods.toml").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No mods.toml present for Forge file.",
|
||||
));
|
||||
}
|
||||
|
||||
if !archive.file_names().any(|name| name.ends_with(".class")) {
|
||||
return Ok(ValidationResult::Warning(
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::models::projects::{GameVersion, Loader};
|
||||
use crate::validate::fabric::FabricValidator;
|
||||
use crate::validate::forge::{ForgeValidator, LegacyForgeValidator};
|
||||
use crate::validate::pack::PackValidator;
|
||||
use crate::validate::quilt::QuiltValidator;
|
||||
use std::io::Cursor;
|
||||
use thiserror::Error;
|
||||
use time::OffsetDateTime;
|
||||
@@ -10,6 +11,7 @@ use zip::ZipArchive;
|
||||
mod fabric;
|
||||
mod forge;
|
||||
mod pack;
|
||||
mod quilt;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ValidationError {
|
||||
@@ -52,11 +54,12 @@ pub trait Validator: Sync {
|
||||
) -> Result<ValidationResult, ValidationError>;
|
||||
}
|
||||
|
||||
static VALIDATORS: [&dyn Validator; 4] = [
|
||||
static VALIDATORS: [&dyn Validator; 5] = [
|
||||
&PackValidator,
|
||||
&FabricValidator,
|
||||
&ForgeValidator,
|
||||
&LegacyForgeValidator,
|
||||
&QuiltValidator,
|
||||
];
|
||||
|
||||
/// The return value is whether this file should be marked as primary or not, based on the analysis of the file
|
||||
|
||||
50
src/validate/quilt.rs
Normal file
50
src/validate/quilt.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use time::OffsetDateTime;
|
||||
use zip::ZipArchive;
|
||||
|
||||
pub struct QuiltValidator;
|
||||
|
||||
impl super::Validator for QuiltValidator {
|
||||
fn get_file_extensions(&self) -> &[&str] {
|
||||
&["jar", "zip"]
|
||||
}
|
||||
|
||||
fn get_project_types(&self) -> &[&str] {
|
||||
&["mod"]
|
||||
}
|
||||
|
||||
fn get_supported_loaders(&self) -> &[&str] {
|
||||
&["fabric"]
|
||||
}
|
||||
|
||||
fn get_supported_game_versions(&self) -> SupportedGameVersions {
|
||||
// Time since release of 18w49a, the first fabric version
|
||||
SupportedGameVersions::PastDate(OffsetDateTime::from_unix_timestamp(
|
||||
1646070100,
|
||||
))
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&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.file_names().any(|name| {
|
||||
name.ends_with("refmap.json") || name.ends_with(".class")
|
||||
}) {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"Quilt mod file is a source file!",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user