Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚨 Run clippy pedantic #469

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions apps/server/src/config/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.map(|origin| origin.to_string())
.chain(local_origins)
.map(|origin| origin.parse())
.filter_map(|res| res.ok())
.filter_map(Result::ok)

Check warning on line 24 in apps/server/src/config/cors.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/config/cors.rs#L24

Added line #L24 was not covered by tests
.collect::<Vec<HeaderValue>>()
}

Expand All @@ -30,9 +30,10 @@

let mut allowed_origins = Vec::new();
for origin in config.allowed_origins {
match origin.parse::<HeaderValue>() {
Ok(val) => allowed_origins.push(val),
Err(_) => tracing::error!("Failed to parse allowed origin: {:?}", origin),
if let Ok(val) = origin.parse::<HeaderValue>() {
allowed_origins.push(val)

Check warning on line 34 in apps/server/src/config/cors.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/config/cors.rs#L33-L34

Added lines #L33 - L34 were not covered by tests
} else {
tracing::error!("Failed to parse allowed origin: {:?}", origin);

Check warning on line 36 in apps/server/src/config/cors.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/config/cors.rs#L36

Added line #L36 was not covered by tests
}
}

Expand All @@ -46,7 +47,9 @@

// Format the local IP with both http and https, and the port. If is_debug is true,
// then also add port 3000.
let local_orgins = if !local_ip.is_empty() {
let local_orgins = if local_ip.is_empty() {
vec![]

Check warning on line 51 in apps/server/src/config/cors.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/config/cors.rs#L50-L51

Added lines #L50 - L51 were not covered by tests
} else {
let port = config.port;
let mut base = vec![
format!("http://{local_ip}:{port}"),
Expand All @@ -61,8 +64,6 @@
}

base
} else {
vec![]
};

let mut cors_layer = CorsLayer::new();
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl From<std::io::Error> for APIError {
}

/// The response body for API errors. This is just a basic JSON response with a status code and a message.
/// Any axum handlers which return a Result with an Error of APIError will be converted into this response.
/// Any axum handlers which return a [`Result`] with an Error of [`APIError`] will be converted into this response.
pub struct APIErrorResponse {
status: StatusCode,
message: String,
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/filter/basic_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
pub relation_filter: MediaMetadataRelationFilter,
}

/// A user-friendly representation of a media's read_progress. This will map to
/// A user-friendly representation of a media's `read_progress`. This will map to
/// a query condition that will be used to filter the media.
#[derive(Default, Debug, Clone, Deserialize, Serialize, ToSchema)]
pub enum ReadStatus {
Expand All @@ -278,7 +278,7 @@
"unread" => Ok(ReadStatus::Unread),
"reading" => Ok(ReadStatus::Reading),
"completed" => Ok(ReadStatus::Completed),
_ => Err(APIError::BadRequest(format!("invalid read status: {}", s))),
_ => Err(APIError::BadRequest(format!("invalid read status: {s}"))),

Check warning on line 281 in apps/server/src/filter/basic_filter.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/filter/basic_filter.rs#L281

Added line #L281 was not covered by tests
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions apps/server/src/middleware/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@
let opds_version = request_uri
.split('/')
.nth(2)
.map(|v| v.replace('v', ""))
.unwrap_or("1.2".to_string());
.map_or("1.2".to_string(), |v| v.replace('v', ""));

Check warning on line 166 in apps/server/src/middleware/auth.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/middleware/auth.rs#L166

Added line #L166 was not covered by tests

return Err(
OPDSBasicAuth::new(opds_version, host_details.url()).into_response()
Expand Down Expand Up @@ -664,7 +663,7 @@
.get("/test")
.add_header(
HeaderName::from_str("Authorization").expect("Failed to create header"),
HeaderValue::from_str(&format!("Bearer {}", access_token))
HeaderValue::from_str(&format!("Bearer {access_token}"))
.expect("Failed to create header"),
)
.await;
Expand Down Expand Up @@ -723,7 +722,7 @@
.get("/test")
.add_header(
HeaderName::from_str("Authorization").expect("Failed to create header"),
HeaderValue::from_str(&format!("Bearer {}", access_token))
HeaderValue::from_str(&format!("Bearer {access_token}"))
.expect("Failed to create header"),
)
.await;
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/routers/api/v1/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
tracing::error!(?error, "Failed to load user's existing session(s)");
Vec::default()
})
.to_owned();
.clone();

Check warning on line 58 in apps/server/src/routers/api/v1/auth.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/auth.rs#L58

Added line #L58 was not covered by tests
let existing_login_sessions_count = existing_sessions.len() as i32;

match (for_user.max_sessions_allowed, existing_login_sessions_count) {
Expand Down Expand Up @@ -396,7 +396,7 @@
let created_user = db
.user()
.create(
input.username.to_owned(),
input.username.clone(),

Check warning on line 399 in apps/server/src/routers/api/v1/auth.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/auth.rs#L399

Added line #L399 was not covered by tests
hashed_password,
vec![user::is_server_owner::set(is_server_owner)],
)
Expand Down
27 changes: 19 additions & 8 deletions apps/server/src/routers/api/v1/book_club.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@
let invalid_role = payload
.role
.as_ref()
.map(|role| *role == BookClubMemberRole::CREATOR)
.unwrap_or(false);
.is_some_and(|role| *role == BookClubMemberRole::CREATOR);

Check warning on line 414 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L414

Added line #L414 was not covered by tests

if invalid_role {
return Err(APIError::BadRequest("Cannot invite a creator".to_string()));
Expand Down Expand Up @@ -833,11 +832,14 @@
},
(Some(start_at), None) => {
let start_at = safe_string_to_date(start_at);
(start_at, start_at + Duration::days(interval_days as i64))
(
start_at,
start_at + Duration::days(i64::from(interval_days)),
)

Check warning on line 838 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L835-L838

Added lines #L835 - L838 were not covered by tests
},
(None, Some(end_at)) => {
let end_at = safe_string_to_date(end_at);
(end_at - Duration::days(interval_days as i64), end_at)
(end_at - Duration::days(i64::from(interval_days)), end_at)

Check warning on line 842 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L842

Added line #L842 was not covered by tests
},
(None, None) => {
let start_at = if let Some(last_end_at) = last_end_at {
Expand All @@ -846,7 +848,10 @@
Utc::now()
};

(start_at, start_at + Duration::days(interval_days as i64))
(
start_at,
start_at + Duration::days(i64::from(interval_days)),
)

Check warning on line 854 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L851-L854

Added lines #L851 - L854 were not covered by tests
},
};

Expand Down Expand Up @@ -1000,11 +1005,14 @@
},
(Some(start_at), None) => {
let start_at = safe_string_to_date(start_at);
(start_at, start_at + Duration::days(interval_days as i64))
(
start_at,
start_at + Duration::days(i64::from(interval_days)),
)

Check warning on line 1011 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L1008-L1011

Added lines #L1008 - L1011 were not covered by tests
},
(None, Some(end_at)) => {
let end_at = safe_string_to_date(end_at);
(end_at - Duration::days(interval_days as i64), end_at)
(end_at - Duration::days(i64::from(interval_days)), end_at)

Check warning on line 1015 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L1015

Added line #L1015 was not covered by tests
},
(None, None) => {
let start_at = if let Some(last_end_at) = last_end_at {
Expand All @@ -1013,7 +1021,10 @@
Utc::now()
};

(start_at, start_at + Duration::days(interval_days as i64))
(
start_at,
start_at + Duration::days(i64::from(interval_days)),
)

Check warning on line 1027 in apps/server/src/routers/api/v1/book_club.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/book_club.rs#L1024-L1027

Added lines #L1024 - L1027 were not covered by tests
},
};

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/routers/api/v1/emailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

// TODO: consider auto truncating?
if include_params.include_send_history {
query = query.with(emailer::send_history::fetch(vec![]))
query = query.with(emailer::send_history::fetch(vec![]));

Check warning on line 104 in apps/server/src/routers/api/v1/emailer.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/emailer.rs#L104

Added line #L104 was not covered by tests
}

let emailers = query
Expand Down
15 changes: 3 additions & 12 deletions apps/server/src/routers/api/v1/epub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@
if let Some(book) = result {
Ok(Json(Epub::try_from(book)?))
} else {
Err(APIError::NotFound(format!(
"Media with id {} not found",
id
)))
Err(APIError::NotFound(format!("Media with id {id} not found")))

Check warning on line 77 in apps/server/src/routers/api/v1/epub.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/epub.rs#L77

Added line #L77 was not covered by tests
}
}

Expand Down Expand Up @@ -281,10 +278,7 @@
if let Some(book) = result {
Ok(EpubProcessor::get_chapter(book.path.as_str(), chapter)?.into())
} else {
Err(APIError::NotFound(format!(
"Media with id {} not found",
id
)))
Err(APIError::NotFound(format!("Media with id {id} not found")))

Check warning on line 281 in apps/server/src/routers/api/v1/epub.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/epub.rs#L281

Added line #L281 was not covered by tests
}
}

Expand Down Expand Up @@ -323,9 +317,6 @@

Ok(BufferResponse::new(content_type, buffer))
} else {
Err(APIError::NotFound(format!(
"Media with id {} not found",
id
)))
Err(APIError::NotFound(format!("Media with id {id} not found")))

Check warning on line 320 in apps/server/src/routers/api/v1/epub.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/epub.rs#L320

Added line #L320 was not covered by tests
}
}
4 changes: 2 additions & 2 deletions apps/server/src/routers/api/v1/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
let listing = std::fs::read_dir(start_path)?;

let files = listing
.filter_map(|res| res.ok())
.filter_map(Result::ok)

Check warning on line 106 in apps/server/src/routers/api/v1/filesystem.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/filesystem.rs#L106

Added line #L106 was not covered by tests
.filter_map(filter_if_hidden)
.map(|entry| DirectoryListingFile::from(entry.path()))
.collect();
Expand Down Expand Up @@ -193,7 +193,7 @@
};

let drive_text = match volume_name {
Some(name) => format!("{} ({})", drive_letter, name),
Some(name) => format!("{drive_letter} ({name})"),
None => drive_letter.clone(),
};

Expand Down
9 changes: 4 additions & 5 deletions apps/server/src/routers/api/v1/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@
},
Pagination::Cursor(cursor_query) => {
if let Some(cursor) = cursor_query.cursor {
query = query.cursor(job::id::equals(cursor)).skip(1)
query = query.cursor(job::id::equals(cursor)).skip(1);

Check warning on line 110 in apps/server/src/routers/api/v1/job.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/job.rs#L110

Added line #L110 was not covered by tests
}
if let Some(limit) = cursor_query.limit {
query = query.take(limit)
query = query.take(limit);

Check warning on line 113 in apps/server/src/routers/api/v1/job.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/job.rs#L113

Added line #L113 was not covered by tests
}
},
_ => unreachable!(),
Expand Down Expand Up @@ -213,13 +213,12 @@
))
.map_err(|e| {
APIError::InternalServerError(format!(
"Failed to send command to job manager: {}",
e
"Failed to send command to job manager: {e}"

Check warning on line 216 in apps/server/src/routers/api/v1/job.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/job.rs#L216

Added line #L216 was not covered by tests
))
})?;

Ok(task_rx.await.map_err(|e| {
APIError::InternalServerError(format!("Failed to get cancel confirmation: {}", e))
APIError::InternalServerError(format!("Failed to get cancel confirmation: {e}"))

Check warning on line 221 in apps/server/src/routers/api/v1/job.rs

View check run for this annotation

Codecov / codecov/patch

apps/server/src/routers/api/v1/job.rs#L221

Added line #L221 was not covered by tests
})??)
}

Expand Down
Loading
Loading