From 079b415ac348fd0dc756e5b3df23d73c097179fe Mon Sep 17 00:00:00 2001 From: Basique Date: Sat, 30 Dec 2023 18:24:53 +0300 Subject: [PATCH] allow uploading custom maven poms as version files --- src/routes/maven.rs | 10 +++++----- src/util/ext.rs | 1 + src/validate/mod.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/routes/maven.rs b/src/routes/maven.rs index aeb9bb88..feb83e0f 100644 --- a/src/routes/maven.rs +++ b/src/routes/maven.rs @@ -298,7 +298,11 @@ pub async fn version_file( return Err(ApiError::NotFound); } - if file == format!("{}-{}.pom", &project_id, &vnum) { + if let Some(selected_file) = find_file(&project_id, &vnum, &version, &file) { + return Ok(HttpResponse::TemporaryRedirect() + .append_header(("location", &*selected_file.url)) + .body("")); + } else if file == format!("{}-{}.pom", &project_id, &vnum) { let respdata = MavenPom { schema_location: "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" @@ -314,10 +318,6 @@ pub async fn version_file( return Ok(HttpResponse::Ok() .content_type("text/xml") .body(yaserde::ser::to_string(&respdata).map_err(ApiError::Xml)?)); - } else if let Some(selected_file) = find_file(&project_id, &vnum, &version, &file) { - return Ok(HttpResponse::TemporaryRedirect() - .append_header(("location", &*selected_file.url)) - .body("")); } Err(ApiError::NotFound) diff --git a/src/util/ext.rs b/src/util/ext.rs index 1f2e9fd3..f936d3a8 100644 --- a/src/util/ext.rs +++ b/src/util/ext.rs @@ -25,6 +25,7 @@ pub fn project_file_type(ext: &str) -> Option<&str> { "jar" => Some("application/java-archive"), "zip" | "litemod" => Some("application/zip"), "mrpack" => Some("application/x-modrinth-modpack+zip"), + "pom" => Some("text/xml"), _ => None, } } diff --git a/src/validate/mod.rs b/src/validate/mod.rs index 90507927..84a70a4d 100644 --- a/src/validate/mod.rs +++ b/src/validate/mod.rs @@ -86,7 +86,7 @@ pub trait Validator: Sync { ) -> Result; } -static ALWAYS_ALLOWED_EXT: &[&str] = &["zip", "txt"]; +static ALWAYS_ALLOWED_EXT: &[&str] = &["zip", "txt", "pom"]; static VALIDATORS: &[&dyn Validator] = &[ &ModpackValidator,