Add deps list for override mods, fix version editing for packs (#363)

This commit is contained in:
Geometrically
2022-06-05 10:42:33 -07:00
committed by GitHub
parent f860f57363
commit e497af4c26
4 changed files with 59 additions and 32 deletions

View File

@@ -696,9 +696,13 @@ pub async fn upload_file(
)
.await?;
if let ValidationResult::PassWithPackData(ref data) = validation_result {
if let ValidationResult::PassWithPackDataAndFiles {
ref format,
ref files,
} = validation_result
{
if dependencies.is_empty() {
let hashes: Vec<Vec<u8>> = data
let hashes: Vec<Vec<u8>> = format
.files
.iter()
.filter_map(|x| x.hashes.get(&PackFileHash::Sha1))
@@ -716,7 +720,7 @@ pub async fn upload_file(
)
.fetch_all(&mut *transaction).await?;
for file in &data.files {
for file in &format.files {
if let Some(dep) = res.iter().find(|x| {
x.hash.as_deref()
== file
@@ -735,24 +739,30 @@ pub async fn upload_file(
});
}
}
} else {
if let Some(first_download) = file.downloads.first() {
dependencies.push(DependencyBuilder {
project_id: None,
version_id: None,
file_name: Some(
first_download
.rsplit('/')
.next()
.unwrap_or(first_download)
.to_string(),
),
dependency_type: DependencyType::Required
} else if let Some(first_download) = file.downloads.first() {
dependencies.push(DependencyBuilder {
project_id: None,
version_id: None,
file_name: Some(
first_download
.rsplit('/')
.next()
.unwrap_or(first_download)
.to_string(),
});
}
),
dependency_type: DependencyType::Required.to_string(),
});
}
}
for file in files {
dependencies.push(DependencyBuilder {
project_id: None,
version_id: None,
file_name: Some(file.to_string()),
dependency_type: DependencyType::Required.to_string(),
});
}
}
}

View File

@@ -72,11 +72,12 @@ pub fn validate_deps(
.iter()
.duplicates_by(|x| {
format!(
"{}-{}",
"{}-{}-{}",
x.version_id
.unwrap_or(crate::models::projects::VersionId(0)),
x.project_id
.unwrap_or(crate::models::projects::ProjectId(0))
.unwrap_or(crate::models::projects::ProjectId(0)),
x.file_name.as_deref().unwrap_or_default()
)
})
.next()

View File

@@ -33,7 +33,10 @@ pub enum ValidationError {
#[derive(Eq, PartialEq)]
pub enum ValidationResult {
/// File should be marked as primary with pack file data
PassWithPackData(PackFormat),
PassWithPackDataAndFiles {
format: PackFormat,
files: Vec<String>,
},
/// File should be marked as primary
Pass,
/// File should not be marked primary, the reason for which is inside the String
@@ -43,7 +46,7 @@ pub enum ValidationResult {
impl ValidationResult {
pub fn is_passed(&self) -> bool {
match self {
ValidationResult::PassWithPackData(_) => true,
ValidationResult::PassWithPackDataAndFiles { .. } => true,
ValidationResult::Pass => true,
ValidationResult::Warning(_) => false,
}

View File

@@ -31,17 +31,19 @@ impl super::Validator for PackValidator {
&self,
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
) -> Result<ValidationResult, ValidationError> {
let mut file =
archive.by_name("modrinth.index.json").map_err(|_| {
ValidationError::InvalidInput(
"Pack manifest is missing.".into(),
)
})?;
let pack: PackFormat = {
let mut file =
archive.by_name("modrinth.index.json").map_err(|_| {
ValidationError::InvalidInput(
"Pack manifest is missing.".into(),
)
})?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let pack: PackFormat = serde_json::from_str(&contents)?;
serde_json::from_str(&contents)?
};
pack.validate().map_err(|err| {
ValidationError::InvalidInput(
@@ -87,6 +89,17 @@ impl super::Validator for PackValidator {
};
}
Ok(ValidationResult::PassWithPackData(pack))
Ok(ValidationResult::PassWithPackDataAndFiles {
format: pack,
files: archive
.file_names()
.filter(|x| {
x.starts_with("overrides/mods")
|| x.starts_with("client-overrides/mods")
|| x.starts_with("server-overrides/mods")
})
.flat_map(|x| x.rsplit('/').next().map(|x| x.to_string()))
.collect::<Vec<String>>(),
})
}
}