You've already forked AstralRinth
forked from didirus/AstralRinth
Fix all default clippy warnings (#480)
All trivial, fixes were for: - #[deny(clippy::if_same_then_else)] - #[warn(clippy::explicit_auto_deref)] - #[warn(clippy::bool_assert_comparison)] Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -168,7 +168,7 @@ pub async fn auth_callback(
|
||||
client: Data<PgPool>,
|
||||
) -> Result<HttpResponse, AuthorizationError> {
|
||||
let mut transaction = client.begin().await?;
|
||||
let state_id = parse_base62(&*info.state)?;
|
||||
let state_id = parse_base62(&info.state)?;
|
||||
|
||||
let result_option = sqlx::query!(
|
||||
"
|
||||
@@ -213,7 +213,7 @@ pub async fn auth_callback(
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
let user = get_github_user_from_token(&*token.access_token).await?;
|
||||
let user = get_github_user_from_token(&token.access_token).await?;
|
||||
|
||||
let user_result =
|
||||
User::get_from_github_id(user.id, &mut *transaction).await?;
|
||||
@@ -241,7 +241,7 @@ pub async fn auth_callback(
|
||||
while username.is_none() {
|
||||
let test_username = format!(
|
||||
"{}{}",
|
||||
&*user.login,
|
||||
&user.login,
|
||||
if username_increment > 0 {
|
||||
username_increment.to_string()
|
||||
} else {
|
||||
@@ -250,7 +250,7 @@ pub async fn auth_callback(
|
||||
);
|
||||
|
||||
let new_id = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*test_username,
|
||||
&test_username,
|
||||
&**client,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -60,7 +60,7 @@ pub async fn maven_metadata(
|
||||
let project_id = params.into_inner().0;
|
||||
let project_data =
|
||||
database::models::Project::get_full_from_slug_or_project_id(
|
||||
&*project_id,
|
||||
&project_id,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -201,7 +201,7 @@ pub async fn handle_stripe_webhook(
|
||||
object: Value,
|
||||
}
|
||||
|
||||
let webhook: StripeWebhookBody = serde_json::from_str(&*body)?;
|
||||
let webhook: StripeWebhookBody = serde_json::from_str(&body)?;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct CheckoutSession {
|
||||
|
||||
@@ -124,7 +124,7 @@ pub async fn notifications_delete(
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
|
||||
let notification_ids =
|
||||
serde_json::from_str::<Vec<NotificationId>>(&*ids.ids)?
|
||||
serde_json::from_str::<Vec<NotificationId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
|
||||
@@ -380,7 +380,7 @@ pub async fn project_create_inner(
|
||||
})?;
|
||||
|
||||
let slug_project_id_option: Option<ProjectId> =
|
||||
serde_json::from_str(&*format!("\"{}\"", create_data.slug)).ok();
|
||||
serde_json::from_str(&format!("\"{}\"", create_data.slug)).ok();
|
||||
|
||||
if let Some(slug_project_id) = slug_project_id_option {
|
||||
let slug_project_id: models::ids::ProjectId =
|
||||
@@ -569,7 +569,7 @@ pub async fn project_create_inner(
|
||||
&content_disposition,
|
||||
project_id,
|
||||
created_version.version_id.into(),
|
||||
&*project_create_data.project_type,
|
||||
&project_create_data.project_type,
|
||||
version_data.loaders.clone(),
|
||||
version_data.game_versions.clone(),
|
||||
all_game_versions.clone(),
|
||||
@@ -875,10 +875,7 @@ async fn create_initial_version(
|
||||
author_id: author.into(),
|
||||
name: version_data.version_title.clone(),
|
||||
version_number: version_data.version_number.clone(),
|
||||
changelog: version_data
|
||||
.version_body
|
||||
.clone()
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
changelog: version_data.version_body.clone().unwrap_or_default(),
|
||||
files: Vec::new(),
|
||||
dependencies,
|
||||
game_versions,
|
||||
|
||||
@@ -24,7 +24,7 @@ pub async fn project_search(
|
||||
web::Query(info): web::Query<SearchRequest>,
|
||||
config: web::Data<SearchConfig>,
|
||||
) -> Result<HttpResponse, SearchError> {
|
||||
let results = search_for_project(&info, &**config).await?;
|
||||
let results = search_for_project(&info, &config).await?;
|
||||
Ok(HttpResponse::Ok().json(results))
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ pub async fn projects_get(
|
||||
web::Query(ids): web::Query<ProjectIds>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let project_ids = serde_json::from_str::<Vec<ProjectId>>(&*ids.ids)?
|
||||
let project_ids = serde_json::from_str::<Vec<ProjectId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
@@ -95,7 +95,7 @@ pub async fn project_get_check(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let slug = info.into_inner().0;
|
||||
|
||||
let id_option = models::ids::base62_impl::parse_base62(&*slug).ok();
|
||||
let id_option = models::ids::base62_impl::parse_base62(&slug).ok();
|
||||
|
||||
let id = if let Some(id) = id_option {
|
||||
let id = sqlx::query!(
|
||||
@@ -745,7 +745,7 @@ pub async fn project_edit(
|
||||
|
||||
if let Some(slug) = slug {
|
||||
let slug_project_id_option: Option<ProjectId> =
|
||||
serde_json::from_str(&*format!("\"{}\"", slug)).ok();
|
||||
serde_json::from_str(&format!("\"{}\"", slug)).ok();
|
||||
if let Some(slug_project_id) = slug_project_id_option {
|
||||
let slug_project_id: database::models::ids::ProjectId =
|
||||
slug_project_id.into();
|
||||
@@ -1006,7 +1006,7 @@ pub async fn project_icon_edit(
|
||||
mut payload: web::Payload,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
if let Some(content_type) =
|
||||
crate::util::ext::get_image_content_type(&*ext.ext)
|
||||
crate::util::ext::get_image_content_type(&ext.ext)
|
||||
{
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
@@ -1183,7 +1183,7 @@ pub async fn add_gallery_item(
|
||||
mut payload: web::Payload,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
if let Some(content_type) =
|
||||
crate::util::ext::get_image_content_type(&*ext.ext)
|
||||
crate::util::ext::get_image_content_type(&ext.ext)
|
||||
{
|
||||
item.validate().map_err(|err| {
|
||||
ApiError::Validation(validation_errors_to_string(err, None))
|
||||
|
||||
@@ -42,7 +42,7 @@ pub async fn report_create(
|
||||
let id =
|
||||
crate::database::models::generate_report_id(&mut transaction).await?;
|
||||
let report_type = crate::database::models::categories::ReportType::get_id(
|
||||
&*new_report.report_type,
|
||||
&new_report.report_type,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
@@ -66,7 +66,7 @@ pub async fn report_create(
|
||||
match new_report.item_type {
|
||||
ItemType::Project => {
|
||||
report.project_id = Some(
|
||||
serde_json::from_str::<ProjectId>(&*format!(
|
||||
serde_json::from_str::<ProjectId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
@@ -75,7 +75,7 @@ pub async fn report_create(
|
||||
}
|
||||
ItemType::Version => {
|
||||
report.version_id = Some(
|
||||
serde_json::from_str::<VersionId>(&*format!(
|
||||
serde_json::from_str::<VersionId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
@@ -84,7 +84,7 @@ pub async fn report_create(
|
||||
}
|
||||
ItemType::User => {
|
||||
report.user_id = Some(
|
||||
serde_json::from_str::<UserId>(&*format!(
|
||||
serde_json::from_str::<UserId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
|
||||
@@ -165,7 +165,7 @@ pub async fn loader_create(
|
||||
.name(&new_loader.name)?
|
||||
.icon(&new_loader.icon)?
|
||||
.supported_project_types(
|
||||
&*project_types.into_iter().map(|x| x.id).collect::<Vec<_>>(),
|
||||
&project_types.into_iter().map(|x| x.id).collect::<Vec<_>>(),
|
||||
)?
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
|
||||
@@ -115,7 +115,7 @@ pub async fn teams_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
use itertools::Itertools;
|
||||
|
||||
let team_ids = serde_json::from_str::<Vec<TeamId>>(&*ids.ids)?
|
||||
let team_ids = serde_json::from_str::<Vec<TeamId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect::<Vec<crate::database::models::ids::TeamId>>();
|
||||
|
||||
@@ -41,7 +41,7 @@ pub async fn users_get(
|
||||
web::Query(ids): web::Query<UserIds>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user_ids = serde_json::from_str::<Vec<UserId>>(&*ids.ids)?
|
||||
let user_ids = serde_json::from_str::<Vec<UserId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
@@ -61,7 +61,7 @@ pub async fn user_get(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let string = info.into_inner().0;
|
||||
let id_option: Option<UserId> =
|
||||
serde_json::from_str(&*format!("\"{}\"", string)).ok();
|
||||
serde_json::from_str(&format!("\"{}\"", string)).ok();
|
||||
|
||||
let mut user_data;
|
||||
|
||||
@@ -92,7 +92,7 @@ pub async fn projects_list(
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await.ok();
|
||||
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
@@ -191,7 +191,7 @@ pub async fn user_edit(
|
||||
})?;
|
||||
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
@@ -415,12 +415,12 @@ pub async fn user_icon_edit(
|
||||
mut payload: web::Payload,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
if let Some(content_type) =
|
||||
crate::util::ext::get_image_content_type(&*ext.ext)
|
||||
crate::util::ext::get_image_content_type(&ext.ext)
|
||||
{
|
||||
let cdn_url = dotenvy::var("CDN_URL")?;
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option =
|
||||
User::get_id_from_username_or_id(&*info.into_inner().0, &**pool)
|
||||
User::get_id_from_username_or_id(&info.into_inner().0, &**pool)
|
||||
.await?;
|
||||
|
||||
if let Some(id) = id_option {
|
||||
@@ -511,8 +511,7 @@ pub async fn user_delete(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option =
|
||||
User::get_id_from_username_or_id(&*info.into_inner().0, &**pool)
|
||||
.await?;
|
||||
User::get_id_from_username_or_id(&info.into_inner().0, &**pool).await?;
|
||||
|
||||
if let Some(id) = id_option {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
@@ -549,7 +548,7 @@ pub async fn user_follows(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
@@ -599,7 +598,7 @@ pub async fn user_notifications(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
@@ -641,8 +640,7 @@ pub async fn user_payouts(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option =
|
||||
User::get_id_from_username_or_id(&*info.into_inner().0, &**pool)
|
||||
.await?;
|
||||
User::get_id_from_username_or_id(&info.into_inner().0, &**pool).await?;
|
||||
|
||||
if let Some(id) = id_option {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
@@ -719,8 +717,7 @@ pub async fn user_payouts_request(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option =
|
||||
User::get_id_from_username_or_id(&*info.into_inner().0, &**pool)
|
||||
.await?;
|
||||
User::get_id_from_username_or_id(&info.into_inner().0, &**pool).await?;
|
||||
|
||||
if let Some(id) = id_option {
|
||||
if !user.role.is_admin() && user.id != id.into() {
|
||||
|
||||
@@ -52,7 +52,7 @@ pub async fn mod_search(
|
||||
web::Query(info): web::Query<SearchRequest>,
|
||||
config: web::Data<SearchConfig>,
|
||||
) -> Result<HttpResponse, SearchError> {
|
||||
let results = search_for_project(&info, &**config).await?;
|
||||
let results = search_for_project(&info, &config).await?;
|
||||
Ok(HttpResponse::Ok().json(SearchResults {
|
||||
hits: results
|
||||
.hits
|
||||
@@ -92,7 +92,7 @@ pub async fn mods_get(
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let project_ids =
|
||||
serde_json::from_str::<Vec<models::ids::ProjectId>>(&*ids.ids)?
|
||||
serde_json::from_str::<Vec<models::ids::ProjectId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
|
||||
@@ -74,7 +74,7 @@ pub async fn report_create(
|
||||
let id =
|
||||
crate::database::models::generate_report_id(&mut transaction).await?;
|
||||
let report_type = crate::database::models::categories::ReportType::get_id(
|
||||
&*new_report.report_type,
|
||||
&new_report.report_type,
|
||||
&mut *transaction,
|
||||
)
|
||||
.await?
|
||||
@@ -98,7 +98,7 @@ pub async fn report_create(
|
||||
match new_report.item_type {
|
||||
ItemType::Mod => {
|
||||
report.project_id = Some(
|
||||
serde_json::from_str::<ProjectId>(&*format!(
|
||||
serde_json::from_str::<ProjectId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
@@ -107,7 +107,7 @@ pub async fn report_create(
|
||||
}
|
||||
ItemType::Version => {
|
||||
report.version_id = Some(
|
||||
serde_json::from_str::<VersionId>(&*format!(
|
||||
serde_json::from_str::<VersionId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
@@ -116,7 +116,7 @@ pub async fn report_create(
|
||||
}
|
||||
ItemType::User => {
|
||||
report.user_id = Some(
|
||||
serde_json::from_str::<UserId>(&*format!(
|
||||
serde_json::from_str::<UserId>(&format!(
|
||||
"\"{}\"",
|
||||
new_report.item_id
|
||||
))?
|
||||
|
||||
@@ -86,7 +86,7 @@ pub async fn loader_create(
|
||||
.name(&name)?
|
||||
.icon(DEFAULT_ICON)?
|
||||
.supported_project_types(
|
||||
&*project_types.into_iter().map(|x| x.id).collect::<Vec<_>>(),
|
||||
&project_types.into_iter().map(|x| x.id).collect::<Vec<_>>(),
|
||||
)?
|
||||
.insert(&mut transaction)
|
||||
.await?;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn mods_list(
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await.ok();
|
||||
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
@@ -59,7 +59,7 @@ pub async fn user_follows(
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let user = get_user_from_headers(req.headers(), &**pool).await?;
|
||||
let id_option = crate::database::models::User::get_id_from_username_or_id(
|
||||
&*info.into_inner().0,
|
||||
&info.into_inner().0,
|
||||
&**pool,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -159,7 +159,7 @@ pub async fn versions_get(
|
||||
ids: web::Query<VersionIds>,
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_ids = serde_json::from_str::<Vec<VersionId>>(&*ids.ids)?
|
||||
let version_ids = serde_json::from_str::<Vec<VersionId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
|
||||
@@ -260,7 +260,7 @@ async fn version_create_inner(
|
||||
changelog: version_create_data
|
||||
.version_body
|
||||
.clone()
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
.unwrap_or_default(),
|
||||
files: Vec::new(),
|
||||
dependencies,
|
||||
game_versions,
|
||||
@@ -304,7 +304,7 @@ async fn version_create_inner(
|
||||
&content_disposition,
|
||||
version.project_id.into(),
|
||||
version.version_id.into(),
|
||||
&*project_type,
|
||||
&project_type,
|
||||
version_data.loaders,
|
||||
version_data.game_versions,
|
||||
all_game_versions.clone(),
|
||||
@@ -585,7 +585,7 @@ async fn upload_file_to_version_inner(
|
||||
&content_disposition,
|
||||
project_id,
|
||||
version_id.into(),
|
||||
&*project_type,
|
||||
&project_type,
|
||||
version.loaders.clone().into_iter().map(Loader).collect(),
|
||||
version
|
||||
.game_versions
|
||||
|
||||
@@ -135,7 +135,7 @@ pub async fn versions_get(
|
||||
pool: web::Data<PgPool>,
|
||||
) -> Result<HttpResponse, ApiError> {
|
||||
let version_ids =
|
||||
serde_json::from_str::<Vec<models::ids::VersionId>>(&*ids.ids)?
|
||||
serde_json::from_str::<Vec<models::ids::VersionId>>(&ids.ids)?
|
||||
.into_iter()
|
||||
.map(|x| x.into())
|
||||
.collect();
|
||||
|
||||
Reference in New Issue
Block a user