Allow setting primary file when creating version (#304)
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
parent
c0c80c0fdf
commit
3ee144459f
@ -1116,21 +1116,6 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"449920c44d498adf8b771973d6034dc97e1c7f3ff4d9d23599af432f294ed564": {
|
||||
"query": "\n INSERT INTO files (id, version_id, url, filename)\n VALUES ($1, $2, $3, $4)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Varchar",
|
||||
"Varchar"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"44bb1034872a80bbea122e04399470fd5f029b819c70cb6e0cb2db6d3193b97e": {
|
||||
"query": "\n INSERT INTO loaders_project_types (joining_loader_id, joining_project_type_id)\n VALUES ($1, $2)\n ",
|
||||
"describe": {
|
||||
@ -5777,6 +5762,22 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"f17dbcc3021d4144f56e9a3bbbf4e0a0087af90e202b9b9d81f1f3622be00e36": {
|
||||
"query": "\n INSERT INTO files (id, version_id, url, filename, is_primary)\n VALUES ($1, $2, $3, $4, $5)\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Int8",
|
||||
"Int8",
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Bool"
|
||||
]
|
||||
},
|
||||
"nullable": []
|
||||
}
|
||||
},
|
||||
"f17df1295edfaa1cac400ce705181b14a9e763f5e515c6913d0152717b89ceaa": {
|
||||
"query": "\n SELECT d.id id\n FROM versions v\n INNER JOIN dependencies d ON d.mod_dependency_id = $1\n INNER JOIN game_versions_versions gvv ON gvv.joining_version_id = v.id AND gvv.game_version_id = ANY($2)\n INNER JOIN loaders_versions lv ON lv.version_id = v.id AND lv.loader_id = ANY($3)\n ",
|
||||
"describe": {
|
||||
|
||||
@ -83,13 +83,14 @@ impl VersionFileBuilder {
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
INSERT INTO files (id, version_id, url, filename)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
INSERT INTO files (id, version_id, url, filename, is_primary)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
",
|
||||
file_id as FileId,
|
||||
version_id as VersionId,
|
||||
self.url,
|
||||
self.filename,
|
||||
self.primary
|
||||
)
|
||||
.execute(&mut *transaction)
|
||||
.await?;
|
||||
|
||||
@ -507,7 +507,8 @@ pub async fn project_create_inner(
|
||||
version_data.loaders.clone(),
|
||||
version_data.game_versions.clone(),
|
||||
all_game_versions.clone(),
|
||||
false,
|
||||
version_data.primary_file.is_some(),
|
||||
version_data.primary_file.as_deref() == Some(name),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -42,6 +42,7 @@ pub struct InitialVersionData {
|
||||
#[validate(length(min = 1))]
|
||||
pub loaders: Vec<Loader>,
|
||||
pub featured: bool,
|
||||
pub primary_file: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
@ -289,7 +290,8 @@ async fn version_create_inner(
|
||||
version_data.loaders,
|
||||
version_data.game_versions,
|
||||
all_game_versions.clone(),
|
||||
false,
|
||||
version_data.primary_file.is_some(),
|
||||
version_data.primary_file.as_deref() == Some(name),
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@ -549,6 +551,7 @@ async fn upload_file_to_version_inner(
|
||||
.collect(),
|
||||
all_game_versions.clone(),
|
||||
true,
|
||||
false,
|
||||
&mut transaction,
|
||||
)
|
||||
.await?;
|
||||
@ -584,6 +587,7 @@ pub async fn upload_file(
|
||||
game_versions: Vec<GameVersion>,
|
||||
all_game_versions: Vec<models::categories::GameVersion>,
|
||||
ignore_primary: bool,
|
||||
force_primary: bool,
|
||||
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
|
||||
) -> Result<(), CreateError> {
|
||||
let (file_name, file_extension) = get_name_ext(content_disposition)?;
|
||||
@ -662,9 +666,10 @@ pub async fn upload_file(
|
||||
hash: upload_data.content_sha512.into_bytes(),
|
||||
},
|
||||
],
|
||||
primary: validation_result == ValidationResult::Pass
|
||||
primary: (validation_result == ValidationResult::Pass
|
||||
&& version_files.iter().all(|x| !x.primary)
|
||||
&& !ignore_primary,
|
||||
&& !ignore_primary)
|
||||
|| force_primary,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user