diff --git a/Cargo.toml b/Cargo.toml index 18abe7b..1f92b83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,10 @@ default = ["mastlogin"] mastlogin = ["reqwest"] [dependencies] -rocket = { version = "=0.5.0-rc.1", features = ["json"] } -rocket_codegen = "=0.5.0-rc.1" -rocket_http = "=0.5.0-rc.1" -rocket_sync_db_pools_codegen = "=0.1.0-rc.1" -rocket_sync_db_pools = { version = "=0.1.0-rc.1", features = ["diesel_postgres_pool"] } +rocket = { version = "=0.5.0-rc.2", features = ["json"] } +rocket_sync_db_pools = { version = "=0.1.0-rc.2", features = ["diesel_postgres_pool"] } diesel = { version = "1.4.8", features = ["postgres", "chrono"] } diesel_migrations = "1.4.0" -tokio = "1.17.0" redis = { version="0.21.5", features = ["aio", "tokio-comp"] } chrono = { version="0.4.19", features = ["serde"] } rand = "0.8.5" @@ -28,5 +24,6 @@ log = "0.4.16" env_logger = "0.9.0" web-push = "0.9.2" url = "2.2.2" +futures = "0.3.24" reqwest = { version = "0.11.10", features = ["json"], optional = true } diff --git a/rust-toolchain b/rust-toolchain index 2bf5ad0..8725364 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -stable +1.64 diff --git a/src/api/attention.rs b/src/api/attention.rs index 4b04fc0..590da25 100644 --- a/src/api/attention.rs +++ b/src/api/attention.rs @@ -108,7 +108,7 @@ pub async fn set_notification(pid: i32, ni: Form, _user: Curre .ok_or(UnknownPushEndpoint)? .to_string(); (url_host.ends_with("googleapis.com") || url_host.ends_with("mozilla.com")) - .then(|| ()) + .then_some(()) .ok_or(UnknownPushEndpoint)?; if ni.enable { diff --git a/src/api/comment.rs b/src/api/comment.rs index 4aeb5ee..b6b3793 100644 --- a/src/api/comment.rs +++ b/src/api/comment.rs @@ -7,9 +7,8 @@ use crate::rds_conn::RdsConn; use crate::rds_models::*; use crate::schema; use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl}; +use futures::{future, join}; use rocket::form::Form; -use rocket::futures::future; -use rocket::futures::join; use rocket::serde::{json::json, Serialize}; use std::collections::HashMap; diff --git a/src/api/mod.rs b/src/api/mod.rs index 0a290f8..80ad830 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_lazy_evaluations)] + use crate::db_conn::Db; use crate::libs::diesel_logger::LoggingConnection; use crate::models::*; diff --git a/src/api/operation.rs b/src/api/operation.rs index 1160080..5cc448a 100644 --- a/src/api/operation.rs +++ b/src/api/operation.rs @@ -108,10 +108,10 @@ pub async fn report(ri: Form, user: CurrentUser, db: Db, rconn: Rds .await? .unwrap_or(0) < 10) - .then(|| ()) + .then_some(()) .ok_or(NotAllowed)?; - (!ri.reason.is_empty()).then(|| ()).ok_or(NoReason)?; + (!ri.reason.is_empty()).then_some(()).ok_or(NoReason)?; let mut p = Post::get(&db, &rconn, ri.pid).await?; if ri.should_hide.is_some() { diff --git a/src/api/post.rs b/src/api/post.rs index 41f5db9..f600499 100644 --- a/src/api/post.rs +++ b/src/api/post.rs @@ -87,23 +87,23 @@ async fn p2output(p: &Post, user: &CurrentUser, db: &Db, rconn: &RdsConn) -> Api Ok(PostOutput { pid: p.id, room_id: p.room_id, - text: can_view.then(|| p.content.clone()).unwrap_or_default(), - cw: (!p.cw.is_empty()).then(|| p.cw.clone()), + text: can_view.then_some(p.content.clone()).unwrap_or_default(), + cw: (!p.cw.is_empty()).then_some(p.cw.clone()), n_attentions: p.n_attentions, n_comments: p.n_comments, create_time: p.create_time.timestamp(), last_comment_time: p.last_comment_time.timestamp(), allow_search: p.allow_search, - author_title: (!p.author_title.is_empty()).then(|| p.author_title.clone()), + author_title: (!p.author_title.is_empty()).then_some(p.author_title.clone()), is_tmp: p.is_tmp, - is_reported: user.is_admin.then(|| p.is_reported), + is_reported: user.is_admin.then_some(p.is_reported), comments: OptionFuture::from( comments.map(|cs| async move { c2output(p, &cs, user, &cached_block_dict).await }), ) .await, can_del: p.check_permission(user, "wd").is_ok(), attention: Attention::init(&user.namehash, rconn).has(p.id).await?, - hot_score: user.is_admin.then(|| p.hot_score), + hot_score: user.is_admin.then_some(p.hot_score), is_blocked, /* blocked_count: if user.is_admin { diff --git a/src/api/vote.rs b/src/api/vote.rs index c74f363..ea76a86 100644 --- a/src/api/vote.rs +++ b/src/api/vote.rs @@ -18,7 +18,7 @@ pub async fn get_poll_dict(pid: i32, rconn: &RdsConn, namehash: &str) -> Option< .has(namehash) .await .unwrap_or_default() - .then(|| opt) + .then_some(opt) })) .await .into_iter() diff --git a/src/cache.rs b/src/cache.rs index 356e8f9..38099ef 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -355,7 +355,7 @@ impl BlockDictCache { let missing: Vec<(String, bool)> = future::try_join_all(hash_list.iter().filter_map(|hash| { - (!block_dict.contains_key(&hash.to_string())).then(|| async { + (!block_dict.contains_key(&hash.to_string())).then_some(async { Ok::<(String, bool), RedisError>(( hash.to_string(), BlockedUsers::check_if_block(&self.rconn, user, hash).await?, diff --git a/src/cors.rs b/src/cors.rs index 96a35e4..5ebe21a 100644 --- a/src/cors.rs +++ b/src/cors.rs @@ -19,11 +19,11 @@ impl Fairing for Cors { } async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) { - if let Some(origin) = request - .headers() - .get_one("Origin") - .and_then(|origin| self.whitelist.contains(&origin.to_string()).then(|| origin)) - { + if let Some(origin) = request.headers().get_one("Origin").and_then(|origin| { + self.whitelist + .contains(&origin.to_string()) + .then_some(origin) + }) { response.set_header(Header::new("Access-Control-Allow-Origin", origin)); response.set_header(Header::new( "Access-Control-Allow-Methods", diff --git a/src/login.rs b/src/login.rs index b0bdd10..22d6ec1 100644 --- a/src/login.rs +++ b/src/login.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unused_unit)] + use crate::db_conn::Db; use crate::models::User; use rocket::request::{FromRequest, Outcome, Request}; diff --git a/src/main.rs b/src/main.rs index 26b4590..61bb536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,17 +28,18 @@ use diesel::Connection; use random_hasher::RandomHasher; use rds_conn::{init_rds_client, RdsConn}; use rds_models::clear_outdate_redis_data; +use rocket::tokio; +use rocket::tokio::time::{sleep, Duration}; use std::env; -use tokio::time::{sleep, Duration}; embed_migrations!("migrations/postgres"); #[rocket::main] -async fn main() -> Result<(), rocket::Error> { +async fn main() { load_env(); if env::args().any(|arg| arg.eq("--init-database")) { init_database(); - return Ok(()); + return; } env_logger::init(); let rmc = init_rds_client().await; @@ -61,7 +62,7 @@ async fn main() -> Result<(), rocket::Error> { } }); - rocket::build() + let _ = rocket::build() .mount( "/_api/v1", routes![ @@ -119,7 +120,7 @@ async fn main() -> Result<(), rocket::Error> { .collect::>(), }) .launch() - .await + .await; } fn load_env() {