diff --git a/src/database/models/charge_item.rs b/src/database/models/charge_item.rs index 55482df9..af0ed0bf 100644 --- a/src/database/models/charge_item.rs +++ b/src/database/models/charge_item.rs @@ -51,7 +51,7 @@ impl TryFrom for ChargeItem { subscription_id: r.subscription_id.map(UserSubscriptionId), subscription_interval: r .subscription_interval - .map(|x| PriceDuration::from_string(&*x)), + .map(|x| PriceDuration::from_string(&x)), }) } } diff --git a/src/file_hosting/backblaze/delete.rs b/src/file_hosting/backblaze/delete.rs index 190288e6..87e24ac3 100644 --- a/src/file_hosting/backblaze/delete.rs +++ b/src/file_hosting/backblaze/delete.rs @@ -15,7 +15,7 @@ pub async fn delete_file_version( file_name: &str, ) -> Result { let response = reqwest::Client::new() - .post(&format!( + .post(format!( "{}/b2api/v2/b2_delete_file_version", authorization_data.api_url )) diff --git a/src/queue/payouts.rs b/src/queue/payouts.rs index e7188c7f..6d1d0c1c 100644 --- a/src/queue/payouts.rs +++ b/src/queue/payouts.rs @@ -74,7 +74,7 @@ impl PayoutsQueue { } let credential: PaypalCredential = client - .post(&format!("{}oauth2/token", dotenvy::var("PAYPAL_API_URL")?)) + .post(format!("{}oauth2/token", dotenvy::var("PAYPAL_API_URL")?)) .header("Accept", "application/json") .header("Accept-Language", "en_US") .header("Authorization", formatted_key) diff --git a/src/routes/internal/billing.rs b/src/routes/internal/billing.rs index 15b9ec0f..b017f5bd 100644 --- a/src/routes/internal/billing.rs +++ b/src/routes/internal/billing.rs @@ -175,19 +175,16 @@ pub async fn edit_subscription( } if let Some(interval) = &edit_subscription.interval { - match ¤t_price.prices { - Price::Recurring { intervals } => { - if let Some(price) = intervals.get(interval) { - open_charge.subscription_interval = Some(*interval); - open_charge.amount = *price as i64; - } else { - return Err(ApiError::InvalidInput( - "Interval is not valid for this subscription!".to_string(), - )); - } + if let Price::Recurring { intervals } = ¤t_price.prices { + if let Some(price) = intervals.get(interval) { + open_charge.subscription_interval = Some(*interval); + open_charge.amount = *price as i64; + } else { + return Err(ApiError::InvalidInput( + "Interval is not valid for this subscription!".to_string(), + )); } - _ => {} - }; + } } open_charge.upsert(&mut transaction).await?; @@ -688,11 +685,7 @@ pub async fn initiate_payment( ( charge.amount, charge.currency_code, - if let Some(interval) = charge.subscription_interval { - Some(interval) - } else { - None - }, + charge.subscription_interval, charge.price_id, Some(id), ) @@ -761,8 +754,7 @@ pub async fn initiate_payment( if user_products .into_iter() - .find(|x| x.product_id == product.id) - .is_some() + .any(|x| x.product_id == product.id) { return Err(ApiError::InvalidInput( "You are already subscribed to this product!".to_string(), @@ -971,11 +963,8 @@ pub async fn stripe_webhook( if let Some(subscription_id) = charge.subscription_id { let mut subscription = if let Some(subscription) = - user_subscription_item::UserSubscriptionItem::get( - subscription_id.into(), - pool, - ) - .await? + user_subscription_item::UserSubscriptionItem::get(subscription_id, pool) + .await? { subscription } else { @@ -1157,21 +1146,19 @@ pub async fn stripe_webhook( if let Err(e) = res { warn!("Error unsuspending pyro server: {:?}", e); } - } else { - if let Some(PaymentRequestMetadata::Pyro { - server_name, - source, - }) = &metadata.payment_metadata - { - let server_name = - server_name.clone().unwrap_or_else(|| { - format!("{}'s server", metadata.user_item.username) - }); - - let res = client - .post("https://archon.pyro.host/v0/servers/create") - .header("X-Master-Key", dotenvy::var("PYRO_API_KEY")?) - .json(&serde_json::json!({ + } else if let Some(PaymentRequestMetadata::Pyro { + server_name, + source, + }) = &metadata.payment_metadata + { + let server_name = server_name.clone().unwrap_or_else(|| { + format!("{}'s server", metadata.user_item.username) + }); + + let res = client + .post("https://archon.pyro.host/v0/servers/create") + .header("X-Master-Key", dotenvy::var("PYRO_API_KEY")?) + .json(&serde_json::json!({ "user_id": to_base62(metadata.user_item.id.0 as u64), "name": server_name, "specs": { @@ -1181,12 +1168,11 @@ pub async fn stripe_webhook( }, "source": source, })) - .send() - .await; + .send() + .await; - if let Err(e) = res { - warn!("Error creating pyro server: {:?}", e); - } + if let Err(e) = res { + warn!("Error creating pyro server: {:?}", e); } } } diff --git a/src/routes/internal/flows.rs b/src/routes/internal/flows.rs index 094e40ff..ef7d395e 100644 --- a/src/routes/internal/flows.rs +++ b/src/routes/internal/flows.rs @@ -510,7 +510,7 @@ impl AuthProvider { map.insert("grant_type", "authorization_code"); let token: AccessToken = reqwest::Client::new() - .post(&format!("{api_url}oauth2/token")) + .post(format!("{api_url}oauth2/token")) .header(reqwest::header::ACCEPT, "application/json") .header( AUTHORIZATION, @@ -766,7 +766,7 @@ impl AuthProvider { let api_url = dotenvy::var("PAYPAL_API_URL")?; let paypal_user: PayPalUser = reqwest::Client::new() - .get(&format!( + .get(format!( "{api_url}identity/openidconnect/userinfo?schema=openid" )) .header(reqwest::header::USER_AGENT, "Modrinth") @@ -1393,7 +1393,7 @@ pub async fn sign_up_beehiiv(email: &str) -> Result<(), AuthenticationError> { let client = reqwest::Client::new(); client - .post(&format!( + .post(format!( "https://api.beehiiv.com/v2/publications/{id}/subscriptions" )) .header(AUTHORIZATION, format!("Bearer {}", api_key)) diff --git a/src/routes/internal/gdpr.rs b/src/routes/internal/gdpr.rs index 8d7f51da..e07855e5 100644 --- a/src/routes/internal/gdpr.rs +++ b/src/routes/internal/gdpr.rs @@ -21,7 +21,7 @@ pub async fn export( &req, &**pool, &redis, - &*session_queue, + &session_queue, Some(&[Scopes::SESSION_ACCESS]), ) .await? @@ -34,19 +34,19 @@ pub async fn export( crate::database::models::Collection::get_many(&collection_ids, &**pool, &redis) .await? .into_iter() - .map(|x| crate::models::collections::Collection::from(x)) + .map(crate::models::collections::Collection::from) .collect::>(); let follows = crate::database::models::User::get_follows(user_id, &**pool) .await? .into_iter() - .map(|x| crate::models::ids::ProjectId::from(x)) + .map(crate::models::ids::ProjectId::from) .collect::>(); let projects = crate::database::models::User::get_projects(user_id, &**pool, &redis) .await? .into_iter() - .map(|x| crate::models::ids::ProjectId::from(x)) + .map(crate::models::ids::ProjectId::from) .collect::>(); let org_ids = crate::database::models::User::get_organizations(user_id, &**pool).await?; @@ -64,7 +64,7 @@ pub async fn export( ) .await? .into_iter() - .map(|x| crate::models::notifications::Notification::from(x)) + .map(crate::models::notifications::Notification::from) .collect::>(); let oauth_clients = @@ -73,7 +73,7 @@ pub async fn export( ) .await? .into_iter() - .map(|x| crate::models::oauth_clients::OAuthClient::from(x)) + .map(crate::models::oauth_clients::OAuthClient::from) .collect::>(); let oauth_authorizations = crate::database::models::oauth_client_authorization_item::OAuthClientAuthorization::get_all_for_user( @@ -81,7 +81,7 @@ pub async fn export( ) .await? .into_iter() - .map(|x| crate::models::oauth_clients::OAuthClientAuthorization::from(x)) + .map(crate::models::oauth_clients::OAuthClientAuthorization::from) .collect::>(); let pat_ids = crate::database::models::pat_item::PersonalAccessToken::get_user_pats( @@ -102,7 +102,7 @@ pub async fn export( let payouts = crate::database::models::payout_item::Payout::get_many(&payout_ids, &**pool) .await? .into_iter() - .map(|x| crate::models::payouts::Payout::from(x)) + .map(crate::models::payouts::Payout::from) .collect::>(); let report_ids = @@ -110,7 +110,7 @@ pub async fn export( let reports = crate::database::models::report_item::Report::get_many(&report_ids, &**pool) .await? .into_iter() - .map(|x| crate::models::reports::Report::from(x)) + .map(crate::models::reports::Report::from) .collect::>(); let message_ids = sqlx::query!( @@ -146,7 +146,7 @@ pub async fn export( crate::database::models::image_item::Image::get_many(&uploaded_images_ids, &**pool, &redis) .await? .into_iter() - .map(|x| crate::models::images::Image::from(x)) + .map(crate::models::images::Image::from) .collect::>(); let subscriptions = @@ -155,7 +155,7 @@ pub async fn export( ) .await? .into_iter() - .map(|x| crate::models::billing::UserSubscription::from(x)) + .map(crate::models::billing::UserSubscription::from) .collect::>(); Ok(HttpResponse::Ok().json(serde_json::json!({ diff --git a/src/routes/v2/version_creation.rs b/src/routes/v2/version_creation.rs index f9422de2..cd4335a1 100644 --- a/src/routes/v2/version_creation.rs +++ b/src/routes/v2/version_creation.rs @@ -106,14 +106,11 @@ pub async fn version_create( // Get all possible side-types for loaders given- we will use these to check if we need to convert/apply singleplayer, etc. let loaders = match v3::tags::loader_list(client.clone(), redis.clone()).await { - Ok(loader_response) => match v2_reroute::extract_ok_json::< - Vec, - >(loader_response) - .await - { - Ok(loaders) => loaders, - Err(_) => vec![], - }, + Ok(loader_response) => { + (v2_reroute::extract_ok_json::>(loader_response) + .await) + .unwrap_or_default() + } Err(_) => vec![], }; diff --git a/src/routes/v3/payouts.rs b/src/routes/v3/payouts.rs index f2d1d6fb..f97844d2 100644 --- a/src/routes/v3/payouts.rs +++ b/src/routes/v3/payouts.rs @@ -352,7 +352,7 @@ pub async fn create_payout( .fetch_optional(&mut *transaction) .await?; - let balance = get_user_balance(user.id.into(), &**pool).await?; + let balance = get_user_balance(user.id, &pool).await?; if balance.available < body.amount || body.amount < Decimal::ZERO { return Err(ApiError::InvalidInput( "You do not have enough funds to make this payout!".to_string(), @@ -734,7 +734,7 @@ pub async fn get_balance( .await? .1; - let balance = get_user_balance(user.id.into(), &**pool).await?; + let balance = get_user_balance(user.id.into(), &pool).await?; Ok(HttpResponse::Ok().json(balance)) }