Skip to content

Commit 9fdeaa6

Browse files
committed
models/krate: Extract max_upload_size() fn
1 parent 4312354 commit 9fdeaa6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/controllers/krate/publish.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ pub async fn publish(app: AppState, req: Parts, body: Body) -> AppResult<Json<Go
147147

148148
let max_upload_size = existing_crate
149149
.as_ref()
150-
.and_then(|c| c.max_upload_size)
151-
.and_then(|m| u32::try_from(m).ok())
150+
.and_then(|c| c.max_upload_size())
152151
.unwrap_or(app.config.max_upload_size);
153152

154153
let tarball_bytes = read_tarball_bytes(&mut reader, max_upload_size).await?;

src/models/krate.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct Crate {
5252
pub homepage: Option<String>,
5353
pub documentation: Option<String>,
5454
pub repository: Option<String>,
55-
pub max_upload_size: Option<i32>,
55+
max_upload_size: Option<i32>,
5656
pub max_features: Option<i16>,
5757
}
5858

@@ -156,6 +156,11 @@ impl<'a> NewCrate<'a> {
156156
}
157157

158158
impl Crate {
159+
pub fn max_upload_size(&self) -> Option<u32> {
160+
self.max_upload_size
161+
.and_then(|size| u32::try_from(size).ok())
162+
}
163+
159164
/// SQL filter based on whether the crate's name loosely matches the given
160165
/// string.
161166
///

0 commit comments

Comments
 (0)