Skip to content

Commit 0f5e197

Browse files
committed
fix: thanks clippy, you're a chill guy
1 parent aa04bc4 commit 0f5e197

File tree

11 files changed

+55
-66
lines changed

11 files changed

+55
-66
lines changed

src/auth/github.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl GithubClient {
9595
ApiError::InternalError
9696
})?;
9797

98-
Ok(github_login_attempts::create(
98+
github_login_attempts::create(
9999
ip,
100100
body.device_code,
101101
body.interval,
@@ -104,7 +104,7 @@ impl GithubClient {
104104
&body.user_code,
105105
&mut *pool,
106106
)
107-
.await?)
107+
.await
108108
}
109109

110110
pub async fn poll_github(
@@ -184,10 +184,10 @@ impl GithubClient {
184184
return Err(ApiError::InternalError);
185185
}
186186

187-
Ok(resp.json::<GitHubFetchedUser>().await.map_err(|e| {
187+
resp.json::<GitHubFetchedUser>().await.map_err(|e| {
188188
log::error!("Failed to create GitHubFetchedUser: {}", e);
189189
ApiError::InternalError
190-
})?)
190+
})
191191
}
192192

193193
pub async fn get_installation(&self, token: &str) -> Result<GitHubFetchedUser, ApiError> {
@@ -222,15 +222,18 @@ impl GithubClient {
222222
let repos = match body.get("repositories").and_then(|r| r.as_array()) {
223223
None => {
224224
return Err(ApiError::InternalError);
225-
},
225+
}
226226
Some(r) => r,
227227
};
228228

229229
if repos.len() != 1 {
230230
return Err(ApiError::InternalError);
231231
}
232232

233-
let owner = repos[0].get("owner").ok_or(ApiError::InternalError)?.clone();
233+
let owner = repos[0]
234+
.get("owner")
235+
.ok_or(ApiError::InternalError)?
236+
.clone();
234237

235238
serde_json::from_value(owner).map_err(|e| {
236239
log::error!("Failed to create GitHubFetchedUser: {}", e);

src/cli/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ pub async fn maybe_cli(data: &AppData) -> anyhow::Result<bool> {
4545
}
4646
JobCommand::CleanupDownloads => {
4747
let mut conn = data.db().acquire().await?;
48-
jobs::cleanup_downloads::cleanup_downloads(&mut *conn).await?;
48+
jobs::cleanup_downloads::cleanup_downloads(&mut conn).await?;
4949

5050
Ok(true)
5151
}
5252
JobCommand::LogoutDeveloper { username } => {
5353
let mut conn = data.db().acquire().await?;
54-
jobs::logout_user::logout_user(&username, &mut *conn).await?;
54+
jobs::logout_user::logout_user(&username, &mut conn).await?;
5555

5656
Ok(true)
5757
}
5858
JobCommand::CleanupTokens => {
5959
let mut conn = data.db().acquire().await?;
60-
jobs::token_cleanup::token_cleanup(&mut *conn).await?;
60+
jobs::token_cleanup::token_cleanup(&mut conn).await?;
6161

6262
Ok(true)
6363
}

src/database/repository/developers.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async fn insert_github(
121121
username: &str,
122122
conn: &mut PgConnection,
123123
) -> Result<Developer, ApiError> {
124-
Ok(sqlx::query_as!(
124+
sqlx::query_as!(
125125
Developer,
126126
"INSERT INTO developers(username, display_name, github_user_id)
127127
VALUES ($1, $1, $2)
@@ -140,11 +140,11 @@ async fn insert_github(
140140
.map_err(|e| {
141141
log::error!("Failed to insert developer: {}", e);
142142
ApiError::DbError
143-
})?)
143+
})
144144
}
145145

146146
pub async fn get_one(id: i32, conn: &mut PgConnection) -> Result<Option<Developer>, ApiError> {
147-
Ok(sqlx::query_as!(
147+
sqlx::query_as!(
148148
Developer,
149149
"SELECT
150150
id,
@@ -162,14 +162,14 @@ pub async fn get_one(id: i32, conn: &mut PgConnection) -> Result<Option<Develope
162162
.map_err(|e| {
163163
log::error!("Failed to fetch developer {}: {}", id, e);
164164
ApiError::DbError
165-
})?)
165+
})
166166
}
167167

168168
pub async fn get_one_by_username(
169169
username: &str,
170170
conn: &mut PgConnection,
171171
) -> Result<Option<Developer>, ApiError> {
172-
Ok(sqlx::query_as!(
172+
sqlx::query_as!(
173173
Developer,
174174
"SELECT
175175
id,
@@ -187,14 +187,14 @@ pub async fn get_one_by_username(
187187
.map_err(|e| {
188188
log::error!("Failed to fetch developer {}: {}", username, e);
189189
ApiError::DbError
190-
})?)
190+
})
191191
}
192192

193193
pub async fn get_all_for_mod(
194194
mod_id: &str,
195195
conn: &mut PgConnection,
196196
) -> Result<Vec<ModDeveloper>, ApiError> {
197-
Ok(sqlx::query_as!(
197+
sqlx::query_as!(
198198
ModDeveloper,
199199
"SELECT
200200
dev.id,
@@ -211,7 +211,7 @@ pub async fn get_all_for_mod(
211211
.map_err(|e| {
212212
log::error!("Failed to fetch developers for mod {}: {}", mod_id, e);
213213
ApiError::DbError
214-
})?)
214+
})
215215
}
216216

217217
pub async fn get_all_for_mods(
@@ -323,7 +323,7 @@ pub async fn get_owner_for_mod(
323323
mod_id: &str,
324324
conn: &mut PgConnection,
325325
) -> Result<Developer, ApiError> {
326-
Ok(sqlx::query_as!(
326+
sqlx::query_as!(
327327
Developer,
328328
"SELECT
329329
dev.id,
@@ -349,7 +349,7 @@ pub async fn get_owner_for_mod(
349349
log::error!("Failed to fetch owner for mod {}", mod_id);
350350
ApiError::InternalError
351351
}
352-
})?)
352+
})
353353
}
354354

355355
pub async fn update_status(
@@ -358,7 +358,7 @@ pub async fn update_status(
358358
admin: bool,
359359
conn: &mut PgConnection,
360360
) -> Result<Developer, ApiError> {
361-
Ok(sqlx::query_as!(
361+
sqlx::query_as!(
362362
Developer,
363363
"UPDATE developers
364364
SET admin = $1,
@@ -380,15 +380,15 @@ pub async fn update_status(
380380
.map_err(|e| {
381381
log::error!("Failed to update developer {}: {}", dev_id, e);
382382
ApiError::DbError
383-
})?)
383+
})
384384
}
385385

386386
pub async fn update_profile(
387387
dev_id: i32,
388388
display_name: &str,
389389
conn: &mut PgConnection,
390390
) -> Result<Developer, ApiError> {
391-
Ok(sqlx::query_as!(
391+
sqlx::query_as!(
392392
Developer,
393393
"UPDATE developers
394394
SET display_name = $1
@@ -408,15 +408,15 @@ pub async fn update_profile(
408408
.map_err(|e| {
409409
log::error!("Failed to update profile for {}: {}", dev_id, e);
410410
ApiError::DbError
411-
})?)
411+
})
412412
}
413413

414414
pub async fn find_by_refresh_token(
415415
uuid: Uuid,
416416
conn: &mut PgConnection,
417417
) -> Result<Option<Developer>, ApiError> {
418418
let hash = sha256::digest(uuid.to_string());
419-
Ok(sqlx::query_as!(
419+
sqlx::query_as!(
420420
Developer,
421421
"SELECT
422422
d.id,
@@ -436,5 +436,5 @@ pub async fn find_by_refresh_token(
436436
.map_err(|e| {
437437
log::error!("Failed to search for developer by refresh token: {}", e);
438438
ApiError::DbError
439-
})?)
439+
})
440440
}

src/database/repository/github_login_attempts.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub async fn get_one_by_ip(
99
ip: IpNetwork,
1010
conn: &mut PgConnection,
1111
) -> Result<Option<StoredLoginAttempt>, ApiError> {
12-
Ok(sqlx::query_as!(
12+
sqlx::query_as!(
1313
StoredLoginAttempt,
1414
"SELECT
1515
uid as uuid,
@@ -30,14 +30,14 @@ pub async fn get_one_by_ip(
3030
.map_err(|e| {
3131
log::error!("Failed to fetch existing login attempt: {}", e);
3232
ApiError::DbError
33-
})?)
33+
})
3434
}
3535

3636
pub async fn get_one_by_uuid(
3737
uuid: Uuid,
3838
pool: &mut PgConnection,
3939
) -> Result<Option<StoredLoginAttempt>, ApiError> {
40-
Ok(sqlx::query_as!(
40+
sqlx::query_as!(
4141
StoredLoginAttempt,
4242
"SELECT
4343
uid as uuid,
@@ -58,7 +58,7 @@ pub async fn get_one_by_uuid(
5858
.map_err(|e| {
5959
log::error!("Failed to fetch GitHub login attempt: {}", e);
6060
ApiError::DbError
61-
})?)
61+
})
6262
}
6363

6464
pub async fn create(
@@ -70,7 +70,7 @@ pub async fn create(
7070
user_code: &str,
7171
pool: &mut PgConnection,
7272
) -> Result<StoredLoginAttempt, ApiError> {
73-
Ok(sqlx::query_as!(
73+
sqlx::query_as!(
7474
StoredLoginAttempt,
7575
"INSERT INTO github_login_attempts
7676
(ip, device_code, interval, expires_in, challenge_uri, user_code) VALUES
@@ -97,7 +97,7 @@ pub async fn create(
9797
.map_err(|e| {
9898
log::error!("Failed to insert new GitHub login attempt: {}", e);
9999
ApiError::DbError
100-
})?)
100+
})
101101
}
102102

103103
pub async fn poll_now(uuid: Uuid, conn: &mut PgConnection) -> Result<(), ApiError> {

src/database/repository/mod_downloads.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub async fn create(
2323
mod_version_id,
2424
e
2525
);
26-
return ApiError::DbError;
26+
ApiError::DbError
2727
})?;
2828

2929
Ok(result.rows_affected() > 0)

src/database/repository/mods.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ pub async fn get_logo(id: &str, conn: &mut PgConnection) -> Result<Option<Vec<u8
4545
log::error!("Failed to fetch mod logo for {}: {}", id, e);
4646
ApiError::DbError
4747
})?
48-
.map(|optional| optional.image)
49-
.flatten();
48+
.and_then(|optional| optional.image);
5049

5150
// Empty vec is basically no image
5251
if vec.as_ref().is_some_and(|v| v.is_empty()) {

src/endpoints/auth/github.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ pub async fn start_github_web_login(data: web::Data<AppData>) -> Result<impl Res
7171
Ok(web::Json(ApiResponse {
7272
error: "".into(),
7373
payload: format!(
74-
"https://github.com/login/oauth/authorize?client_id={}&redirect_uri={}&scope=read:user&state={}",
74+
"https://github.com/login/oauth/authorize?client_id={}&redirect_uri={}/login/github/callback&scope=read:user&state={}",
7575
data.github().client_id(),
76-
format!("{}/login/github/callback", data.front_url()),
77-
secret.to_string()
76+
data.front_url(),
77+
secret
7878
),
7979
}))
8080
}

src/endpoints/mod_versions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub async fn create_version(
304304
let approved_count = ModVersion::get_accepted_count(&json.id, &mut pool).await?;
305305

306306
if dev.verified && approved_count != 0 {
307-
let owner = developers::get_owner_for_mod(&json.id, &mut *pool).await?;
307+
let owner = developers::get_owner_for_mod(&json.id, &mut pool).await?;
308308

309309
NewModVersionAcceptedEvent {
310310
id: json.id.clone(),
@@ -315,7 +315,7 @@ pub async fn create_version(
315315
base_url: data.app_url().to_string(),
316316
}
317317
.to_discord_webhook()
318-
.send(&data.webhook_url());
318+
.send(data.webhook_url());
319319
}
320320
Ok(HttpResponse::NoContent())
321321
}
@@ -400,7 +400,7 @@ pub async fn update_version(
400400
base_url: data.app_url().to_string(),
401401
}
402402
.to_discord_webhook()
403-
.send(&data.webhook_url());
403+
.send(data.webhook_url());
404404
} else {
405405
NewModVersionAcceptedEvent {
406406
id: version.mod_id,
@@ -411,7 +411,7 @@ pub async fn update_version(
411411
base_url: data.app_url().to_string(),
412412
}
413413
.to_discord_webhook()
414-
.send(&data.webhook_url());
414+
.send(data.webhook_url());
415415
}
416416
}
417417

src/extractors/auth.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Auth {
3737

3838
match self.developer.as_ref().is_some_and(|dev| dev.admin) {
3939
false => Err(ApiError::Forbidden),
40-
true => Ok(())
40+
true => Ok(()),
4141
}
4242
}
4343
}
@@ -105,17 +105,14 @@ impl FromRequest for Auth {
105105

106106
fn parse_token(map: &HeaderMap) -> Option<Uuid> {
107107
map.get("Authorization")
108-
.map(|header| header.to_str().ok())
109-
.flatten()
110-
.map(|str| -> Option<&str> {
108+
.and_then(|header| header.to_str().ok())
109+
.and_then(|str| -> Option<&str> {
111110
let split = str.split(' ').collect::<Vec<&str>>();
112111
if split.len() != 2 || split[0] != "Bearer" {
113112
None
114113
} else {
115114
Some(split[1])
116115
}
117116
})
118-
.flatten()
119-
.map(|str| Uuid::try_parse(str).ok())
120-
.flatten()
117+
.and_then(|str| Uuid::try_parse(str).ok())
121118
}

0 commit comments

Comments
 (0)