Skip to content

Commit

Permalink
models/krate: Extract max_upload_size() fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Nov 28, 2024
1 parent 4312354 commit 9fdeaa6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go

let max_upload_size = existing_crate
.as_ref()
.and_then(|c| c.max_upload_size)
.and_then(|m| u32::try_from(m).ok())
.and_then(|c| c.max_upload_size())
.unwrap_or(app.config.max_upload_size);

let tarball_bytes = read_tarball_bytes(&mut reader, max_upload_size).await?;
Expand Down
7 changes: 6 additions & 1 deletion src/models/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct Crate {
pub homepage: Option<String>,
pub documentation: Option<String>,
pub repository: Option<String>,
pub max_upload_size: Option<i32>,
max_upload_size: Option<i32>,
pub max_features: Option<i16>,
}

Expand Down Expand Up @@ -156,6 +156,11 @@ impl<'a> NewCrate<'a> {
}

impl Crate {
pub fn max_upload_size(&self) -> Option<u32> {
self.max_upload_size
.and_then(|size| u32::try_from(size).ok())
}

/// SQL filter based on whether the crate's name loosely matches the given
/// string.
///
Expand Down

0 comments on commit 9fdeaa6

Please sign in to comment.