Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Oct 10, 2024
1 parent 8900a1d commit 9b068d4
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/database/models/charge_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TryFrom<ChargeResult> 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)),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/file_hosting/backblaze/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn delete_file_version(
file_name: &str,
) -> Result<DeleteFileData, FileHostingError> {
let response = reqwest::Client::new()
.post(&format!(
.post(format!(
"{}/b2api/v2/b2_delete_file_version",
authorization_data.api_url
))
Expand Down
2 changes: 1 addition & 1 deletion src/queue/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 30 additions & 44 deletions src/routes/internal/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,16 @@ pub async fn edit_subscription(
}

if let Some(interval) = &edit_subscription.interval {
match &current_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 } = &current_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?;
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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": {
Expand All @@ -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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/routes/internal/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down
22 changes: 11 additions & 11 deletions src/routes/internal/gdpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn export(
&req,
&**pool,
&redis,
&*session_queue,
&session_queue,
Some(&[Scopes::SESSION_ACCESS]),
)
.await?
Expand All @@ -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::<Vec<_>>();

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::<Vec<_>>();

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::<Vec<_>>();

let org_ids = crate::database::models::User::get_organizations(user_id, &**pool).await?;
Expand All @@ -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::<Vec<_>>();

let oauth_clients =
Expand All @@ -73,15 +73,15 @@ pub async fn export(
)
.await?
.into_iter()
.map(|x| crate::models::oauth_clients::OAuthClient::from(x))
.map(crate::models::oauth_clients::OAuthClient::from)
.collect::<Vec<_>>();

let oauth_authorizations = crate::database::models::oauth_client_authorization_item::OAuthClientAuthorization::get_all_for_user(
user_id, &**pool,
)
.await?
.into_iter()
.map(|x| crate::models::oauth_clients::OAuthClientAuthorization::from(x))
.map(crate::models::oauth_clients::OAuthClientAuthorization::from)
.collect::<Vec<_>>();

let pat_ids = crate::database::models::pat_item::PersonalAccessToken::get_user_pats(
Expand All @@ -102,15 +102,15 @@ 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::<Vec<_>>();

let report_ids =
crate::database::models::user_item::User::get_reports(user_id, &**pool).await?;
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::<Vec<_>>();

let message_ids = sqlx::query!(
Expand Down Expand Up @@ -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::<Vec<_>>();

let subscriptions =
Expand All @@ -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::<Vec<_>>();

Ok(HttpResponse::Ok().json(serde_json::json!({
Expand Down
13 changes: 5 additions & 8 deletions src/routes/v2/version_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<v3::tags::LoaderData>,
>(loader_response)
.await
{
Ok(loaders) => loaders,
Err(_) => vec![],
},
Ok(loader_response) => {
(v2_reroute::extract_ok_json::<Vec<v3::tags::LoaderData>>(loader_response)
.await)
.unwrap_or_default()
}
Err(_) => vec![],
};

Expand Down
4 changes: 2 additions & 2 deletions src/routes/v3/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 9b068d4

Please sign in to comment.