Skip to content

Commit

Permalink
chore: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Oct 28, 2024
1 parent 33ca0a0 commit 82b7d30
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 52 deletions.
32 changes: 13 additions & 19 deletions crates/api_admin/src/routes/block_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@ pub async fn block_url(
) -> Result<(StatusCode, Json<BlockUrlResult>), AppError> {
match &query.url {
url if url.query().is_some() => Err(AppError::new(
format!(
"wrong url: {} (can't contain search params)",
url.to_string()
),
format!("wrong url: {} (can't contain search params)", url),
None,
Some(StatusCode::BAD_REQUEST),
)),
_ => match BlockedUrl::find_by_id(&query.url.to_string())
.one(&data.conn)
.await?
{
Some(url) => Err(AppError::new(
format!("The url already blocked: {}", url.id),
None,
Some(StatusCode::BAD_REQUEST),
)),
None => {
_ =>
if let Some(url) = BlockedUrl::find_by_id(query.url.to_string())
.one(&data.conn)
.await?
{
Err(AppError::new(
format!("The url already blocked: {}", url.id),
None,
Some(StatusCode::BAD_REQUEST),
))
} else {
blocked_url::ActiveModel {
id: Set(query.url.to_string()),
is_instance: Set(query.url.path().eq("/")),
Expand All @@ -56,13 +54,9 @@ pub async fn block_url(
StatusCode::OK,
Json(BlockUrlResult {
url: query.url.clone(),
message: format!(
"The url was successfully blocked: {}",
&query.url.to_string()
),
message: format!("The url was successfully blocked: {}", &query.url),
}),
))
},
},
}
}
9 changes: 3 additions & 6 deletions crates/api_admin/src/routes/unblock_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn unblock_url(
data: Data<AppData>,
query: Query<BlockUrlQuery>,
) -> Result<(StatusCode, Json<BlockUrlResult>), AppError> {
match BlockedUrl::find_by_id(&query.url.to_string())
match BlockedUrl::find_by_id(query.url.to_string())
.one(&data.conn)
.await?
{
Expand All @@ -37,15 +37,12 @@ pub async fn unblock_url(
StatusCode::OK,
Json(BlockUrlResult {
url: query.url.clone(),
message: format!(
"The url was successfully unblocked: {}",
&query.url.to_string()
),
message: format!("The url was successfully unblocked: {}", &query.url),
}),
))
},
None => Err(AppError::new(
format!("The url doesn't exist: {}", query.url.to_string()),
format!("The url doesn't exist: {}", query.url),
None,
Some(StatusCode::BAD_REQUEST),
)),
Expand Down
1 change: 1 addition & 0 deletions crates/api_apub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub const TAG: &str = "apub";
)]
pub struct ApubApi;

#[must_use]
pub fn routes() -> OpenApiRouter {
OpenApiRouter::with_openapi(ApubApi::openapi())
.merge(activities::routes())
Expand Down
2 changes: 1 addition & 1 deletion crates/api_apub/src/users/user_followers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub async fn handler(
.into_iter()
.map(|follow| Url::parse(&follow.id))
.filter_map(Result::ok)
.map(|url| serde_json::to_value(url))
.map(serde_json::to_value)
.filter_map(Result::ok)
.collect(),
total.number_of_pages,
Expand Down
4 changes: 2 additions & 2 deletions crates/api_mastodon/src/entities/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ impl Instance {
.env
.hatsu_node_name
.as_deref()
.unwrap_or_else(|| "Hatsu")
.unwrap_or("Hatsu")
.to_string(),
version: String::from(VERSION),
source_url: Url::parse("https://github.com/importantimport/hatsu")?,
description: data
.env
.hatsu_node_description
.as_deref()
.unwrap_or_else(|| env!("CARGO_PKG_DESCRIPTION"))
.unwrap_or(env!("CARGO_PKG_DESCRIPTION"))
.to_string(),
usage: json!({
"users": {
Expand Down
1 change: 1 addition & 0 deletions crates/api_mastodon/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub const TAG: &str = "mastodon";
)]
pub struct MastodonApi;

#[must_use]
pub fn routes() -> OpenApiRouter {
OpenApiRouter::with_openapi(MastodonApi::openapi())
.merge(instance::routes())
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/create_or_update/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ActivityHandler for CreateOrUpdateNote {
async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// TODO
ApubPost::verify(&self.object, &self.id, data).await?;
verify_blocked(&self.actor(), data).await?;
verify_blocked(self.actor(), data).await?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/following/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ActivityHandler for Follow {

async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// TODO
verify_blocked(&self.actor(), data).await?;
verify_blocked(self.actor(), data).await?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/following/undo_follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ActivityHandler for UndoFollow {

async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// TODO
verify_blocked(&self.actor(), data).await?;
verify_blocked(self.actor(), data).await?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ActivityHandler for LikeOrAnnounce {

async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// TODO
verify_blocked(&self.actor(), data).await?;
verify_blocked(self.actor(), data).await?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ActivityHandler for UndoLikeOrAnnounce {

async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
// TODO
verify_blocked(&self.actor(), data).await?;
verify_blocked(self.actor(), data).await?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/actors/db_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Object for ApubUser {
icon: self
.icon
.as_deref()
.and_then(|icon| Url::parse(&icon).map_or(None, |url| Some(UserImage::new(url)))),
.and_then(|icon| Url::parse(icon).map_or(None, |url| Some(UserImage::new(url)))),
image: self.hatsu.clone().and_then(|hatsu| {
hatsu.banner_image.and_then(|image| {
Url::parse(&image).map_or(None, |url| Some(UserImage::new(url)))
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/actors/db_user_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ApubUser {
hatsu: self.hatsu.clone().map(UserFeedHatsu::from_db),
title: self.name.clone(),
description: self.summary.clone(),
icon: self.icon.as_deref().and_then(|url| Url::parse(&url).ok()),
icon: self.icon.as_deref().and_then(|url| Url::parse(url).ok()),
language: self.language.clone(),
feed_url: Url::parse("https://hatsu.local").unwrap(),
next_url: Option::default(),
Expand Down
5 changes: 4 additions & 1 deletion crates/apub/src/objects/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ impl Note {
to: vec![public()],
// Leaving a CC here to retain compatibility, figured I should CC followers instead of public twice
cc: vec![Url::parse(&format!("{}/followers", actor.id()))?],
content_map: generate_map(&content, json.language.or(top_level.language.clone())),
content_map: generate_map(
&content,
json.language.or_else(|| top_level.language.clone()),
),
content,
source: Some(serde_json::to_value(NoteSource::new(source))?),
tag: json.tags.map_or_else(Vec::new, |tags| {
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/utils/verify_blocked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn verify_blocked(url: &Url, data: &Data<AppData>) -> Result<(), AppEr
.any(|actor| url.eq(&actor))
{
Err(AppError::new(
format!("blocked actor: {}", url),
format!("blocked actor: {url}"),
None,
Some(StatusCode::BAD_REQUEST),
))
Expand Down
2 changes: 1 addition & 1 deletion crates/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub async fn run(federation_config: FederationConfig<AppData>) -> Result<(), App
.with_graceful_shutdown(async {
hatsu_utils::shutdown_signal()
.await
.expect("failed to install graceful shutdown handler")
.expect("failed to install graceful shutdown handler");
})
.await?;

Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240131_000001_user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{boolean, string, string_null},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240131_000002_user_feed_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{string, string_null},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240131_000003_post.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{boolean, string, string_null, text},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240131_000004_activity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{json, string, string_null},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240131_000005_received_follow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{string, text_null},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
2 changes: 1 addition & 1 deletion crates/db_migration/src/m20240501_000001_received_like.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{prelude::*, schema::string};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{prelude::*, schema::string};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{json_null, string_null},
};

use crate::{m20240131_000001_user::User, m20240131_000002_user_feed_item::UserFeedItem};

Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240515_000002_user_feed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{json_null, string_null},
};

use crate::m20240131_000001_user::User;

Expand Down
5 changes: 4 additions & 1 deletion crates/db_migration/src/m20240926_000001_blocked_url.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{
prelude::*,
schema::{boolean, string},
};

#[derive(DeriveMigrationName)]
pub struct Migration;
Expand Down
2 changes: 1 addition & 1 deletion crates/db_migration/src/m20241028_000001_user_language.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sea_orm_migration::{prelude::*, schema::*};
use sea_orm_migration::{prelude::*, schema::string_null};

use crate::m20240131_000001_user::User;

Expand Down
4 changes: 2 additions & 2 deletions crates/feed/src/user_feed_top_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl UserFeedTopLevel {
None => String::from("untitled"),
},
description: feed.description.map(|text| text.content),
icon: feed.icon.map_or(
feed.logo.and_then(|image| Url::parse(&image.uri).ok()),
icon: feed.icon.map_or_else(
|| feed.logo.and_then(|image| Url::parse(&image.uri).ok()),
|image| Url::parse(&image.uri).ok(),
),
language: feed.language,
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/version.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

0 comments on commit 82b7d30

Please sign in to comment.