Skip to content

Commit a76c39e

Browse files
committed
fix(mod_version): small changes to create_version
1 parent b2ab2b9 commit a76c39e

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/endpoints/mod_versions.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub async fn create_version(
278278
})
279279
.count();
280280

281-
let verified = match accepted_versions {
281+
let make_accepted = match accepted_versions {
282282
0 => false,
283283
_ => dev.verified,
284284
};
@@ -291,7 +291,7 @@ pub async fn create_version(
291291
.collect();
292292

293293
let bytes = download_mod(&download_link, data.max_download_mb()).await?;
294-
let json = ModJson::from_zip(bytes, &download_link, verified).map_err(|err| {
294+
let json = ModJson::from_zip(bytes, &download_link, make_accepted).map_err(|err| {
295295
log::error!("Failed to parse mod.json: {}", err);
296296
ApiError::FilesystemError
297297
})?;
@@ -307,7 +307,7 @@ pub async fn create_version(
307307
let mut tx = pool.begin().await.or(Err(ApiError::TransactionError))?;
308308

309309
let mut version: ModVersion = if versions.is_empty() {
310-
mod_versions::create_from_json(&json, verified, &mut tx).await?
310+
mod_versions::create_from_json(&json, make_accepted, &mut tx).await?
311311
} else {
312312
let latest = versions.first().unwrap();
313313
let latest_version = semver::Version::parse(&latest.version)
@@ -317,9 +317,16 @@ pub async fn create_version(
317317
ApiError::BadRequest(format!("Invalid mod.json version: {}", json.version)),
318318
))?;
319319

320-
if new_version <= latest_version {
320+
if new_version == latest_version {
321321
return Err(ApiError::BadRequest(format!(
322-
"mod.json version {} is smaller / equal to latest mod version {}",
322+
"mod.json has the same version as the latest version: {}",
323+
new_version
324+
)));
325+
}
326+
327+
if new_version < latest_version {
328+
return Err(ApiError::BadRequest(format!(
329+
"mod.json version {} is less than latest mod version {}",
323330
json.version, latest_version
324331
)));
325332
}
@@ -329,9 +336,9 @@ pub async fn create_version(
329336
dependencies::clear(latest.id, &mut tx).await?;
330337
incompatibilities::clear(latest.id, &mut tx).await?;
331338
mod_gd_versions::clear(latest.id, &mut tx).await?;
332-
mod_versions::update_pending_version(latest.id, &json, verified, &mut tx).await?
339+
mod_versions::update_pending_version(latest.id, &json, make_accepted, &mut tx).await?
333340
} else {
334-
mod_versions::create_from_json(&json, verified, &mut tx).await?
341+
mod_versions::create_from_json(&json, make_accepted, &mut tx).await?
335342
}
336343
};
337344

@@ -351,7 +358,7 @@ pub async fn create_version(
351358
.collect(),
352359
);
353360

354-
if verified || accepted_versions == 0 {
361+
if make_accepted {
355362
if let Some(links) = json.links.clone() {
356363
mod_links::upsert(
357364
&the_mod.id,
@@ -374,7 +381,7 @@ pub async fn create_version(
374381

375382
tx.commit().await.or(Err(ApiError::TransactionError))?;
376383

377-
if verified {
384+
if make_accepted {
378385
let owner = developers::get_owner_for_mod(&version.mod_id, &mut pool).await?;
379386

380387
NewModVersionAcceptedEvent {

0 commit comments

Comments
 (0)