@@ -124,6 +124,25 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
124124 ( existing_crate, auth)
125125 } ;
126126
127+ let verified_email_address = auth. user ( ) . async_verified_email ( & mut conn) . await ?;
128+ let verified_email_address = verified_email_address. ok_or_else ( || {
129+ bad_request ( format ! (
130+ "A verified email address is required to publish crates to crates.io. \
131+ Visit https://{}/settings/profile to set and verify your email address.",
132+ app. config. domain_name,
133+ ) )
134+ } ) ?;
135+
136+ // Use a different rate limit whether this is a new or an existing crate.
137+ let rate_limit_action = match existing_crate {
138+ Some ( _) => LimitedAction :: PublishUpdate ,
139+ None => LimitedAction :: PublishNew ,
140+ } ;
141+
142+ app. rate_limiter
143+ . check_rate_limit ( auth. user ( ) . id , rate_limit_action, & mut conn)
144+ . await ?;
145+
127146 spawn_blocking ( move || {
128147 use diesel:: RunQueryDsl ;
129148
@@ -132,23 +151,6 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
132151 let api_token_id = auth. api_token_id ( ) ;
133152 let user = auth. user ( ) ;
134153
135- let verified_email_address = user. verified_email ( conn) ?;
136- let verified_email_address = verified_email_address. ok_or_else ( || {
137- bad_request ( format ! (
138- "A verified email address is required to publish crates to crates.io. \
139- Visit https://{}/settings/profile to set and verify your email address.",
140- app. config. domain_name,
141- ) )
142- } ) ?;
143-
144- // Use a different rate limit whether this is a new or an existing crate.
145- let rate_limit_action = match existing_crate {
146- Some ( _) => LimitedAction :: PublishUpdate ,
147- None => LimitedAction :: PublishNew ,
148- } ;
149- app. rate_limiter
150- . check_rate_limit ( user. id , rate_limit_action, conn) ?;
151-
152154 let content_length = tarball_bytes. len ( ) as u64 ;
153155
154156 let maximums = Maximums :: new (
@@ -226,7 +228,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
226228 validate_url ( homepage. as_deref ( ) , "homepage" ) ?;
227229 validate_url ( documentation. as_deref ( ) , "documentation" ) ?;
228230 validate_url ( repository. as_deref ( ) , "repository" ) ?;
229- if let Some ( ref rust_version) = rust_version {
231+ if let Some ( ref rust_version) = rust_version {
230232 validate_rust_version ( rust_version) ?;
231233 }
232234
@@ -495,7 +497,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
495497 repository,
496498 pkg_path_in_vcs,
497499 )
498- . enqueue ( conn) ?;
500+ . enqueue ( conn) ?;
499501 }
500502 }
501503
@@ -556,7 +558,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
556558 } ) )
557559 } )
558560 } )
559- . await
561+ . await
560562}
561563
562564/// Counts the number of versions for `crate_id` that were published within
0 commit comments