Skip to content

Commit

Permalink
chore: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed May 2, 2024
1 parent 6f28225 commit 8f288fc
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 30 deletions.
6 changes: 4 additions & 2 deletions crates/api_mastodon/src/entities/custom_emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct CustomEmoji {
}

impl CustomEmoji {
#[must_use]
pub fn from_json(tags: Vec<Tag>) -> Vec<Self> {
tags.into_iter()
.filter_map(|tag| match tag {
Expand All @@ -24,12 +25,13 @@ impl CustomEmoji {
.collect()
}

#[must_use]
pub fn from_emoji(emoji: Emoji) -> Self {
Self {
shortcode: emoji
.name
.trim_start_matches(":")
.trim_end_matches(":")
.trim_start_matches(':')
.trim_end_matches(':')
.to_string(),
url: emoji.icon.url.clone(),
static_url: emoji.icon.url,
Expand Down
10 changes: 5 additions & 5 deletions crates/api_mastodon/src/entities/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ impl Instance {
.env
.hatsu_node_name
.clone()
.unwrap_or(String::from("Hatsu")),
.unwrap_or_else(|| String::from("Hatsu")),
version: String::from(env!("CARGO_PKG_VERSION")),
source_url: Url::parse("https://github.com/importantimport/hatsu")?,
description: data
.env
.hatsu_node_description
.clone()
.unwrap_or(String::from(env!("CARGO_PKG_DESCRIPTION"))),
.unwrap_or_else(|| String::from(env!("CARGO_PKG_DESCRIPTION"))),
usage: json!({
"users": {
"active_month": 0
Expand Down Expand Up @@ -71,7 +71,7 @@ pub struct InstanceContact {
impl InstanceContact {
pub async fn new(data: &Data<AppData>) -> Result<Self, AppError> {
Ok(Self {
email: String::from(""),
email: String::new(),
account: Account::primary_account(data).await?,
})
}
Expand Down Expand Up @@ -99,14 +99,14 @@ pub struct InstanceV1 {
}

impl InstanceV1 {
pub async fn from_instance(instance: Instance) -> Result<Self, AppError> {
pub fn from_instance(instance: Instance) -> Result<Self, AppError> {
Ok(Self {
uri: instance.domain.clone(),
title: instance.title,
short_description: instance.description.clone(),
description: instance.description,
// TODO: env HATSU_CONTACT_EMAIL
email: String::from(""),
email: String::new(),
version: instance.version,
urls: json!({}),
stats: json!({}),
Expand Down
2 changes: 1 addition & 1 deletion crates/api_mastodon/src/routes/instance/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ pub async fn v2(data: Data<AppData>) -> Result<Json<Instance>, AppError> {
#[debug_handler]
pub async fn v1(data: Data<AppData>) -> Result<Json<InstanceV1>, AppError> {
Ok(Json(
InstanceV1::from_instance(Instance::new(&data).await?).await?,
InstanceV1::from_instance(Instance::new(&data).await?)?,
))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use activitypub_federation::config::Data;
use axum::{debug_handler, extract::Path, Json};
use hatsu_db_schema::prelude::{Post, ReceivedLike};
use hatsu_utils::{AppData, AppError};
use sea_orm::*;
use sea_orm::{EntityTrait, ModelTrait};

use crate::entities::Account;

Expand All @@ -28,7 +28,6 @@ pub async fn status_favourited_by(
Path(base64_url): Path<String>,
data: Data<AppData>,
) -> Result<Json<Vec<Account>>, AppError> {
// Ok(Json(vec![Account::primary_account(&data).await?]))
let base64 = base64_simd::URL_SAFE;

match base64.decode_to_vec(&base64_url) {
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 @@ -103,7 +103,7 @@ impl ActivityHandler for CreateOrUpdateNote {
async fn receive(self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
match self.kind {
CreateOrUpdateType::CreateType(_) => ApubPost::from_json(self.object, data).await?,
_ => todo!(), // TODO
CreateOrUpdateType::UpdateType(_) => todo!(), // TODO
};

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/like/db_received_like_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl ApubReceivedLike {
})
}

pub fn from_json(json: Like) -> Result<Self, AppError> {
pub fn from_json(json: &Like) -> Result<Self, AppError> {
Ok(DbReceivedLike {
id: json.id.to_string(),
actor: json.actor.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/like/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ActivityHandler for Like {
.await?
.is_none()
{
ApubReceivedLike::from_json(self)?
ApubReceivedLike::from_json(&self)?
.deref()
.clone()
.into_active_model()
Expand Down
10 changes: 5 additions & 5 deletions crates/apub/src/objects/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub struct Note {
pub source: Option<Value>,
#[serde(default, deserialize_with = "deserialize_one_or_many")]
pub tag: Vec<Tag>,
/// https://www.w3.org/ns/activitystreams#url
/// https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md
/// <https://www.w3.org/ns/activitystreams#url>
/// <https://codeberg.org/fediverse/fep/src/branch/main/fep/fffd/fep-fffd.md>
pub url: Option<Value>,
// TODO:
// sensitive (default: false) (extension: _hatsu.sensitive)
Expand Down Expand Up @@ -128,15 +128,15 @@ impl Note {
id,
kind: NoteType::Note,
in_reply_to: None,
published: published.unwrap_or_else(|| hatsu_utils::date::now()),
published: published.unwrap_or_else(hatsu_utils::date::now),
updated,
attributed_to: actor.id().into(),
to: vec![Url::parse(&format!("{}/followers", actor.id()))?],
cc: vec![public()],
content,
source: Some(serde_json::to_value(NoteSource::new(source))?),
tag: json.tags.map_or_else(
|| vec![],
|| Vec::new(),
|tags| {
tags.into_iter()
.map(|tag| {
Expand Down Expand Up @@ -229,7 +229,7 @@ pub struct NoteSource {
}

impl NoteSource {
pub fn new(source: String) -> Self {
pub const fn new(source: String) -> Self {
Self {
content: source,
media_type: MediaTypeMarkdown::Markdown,
Expand Down
1 change: 1 addition & 0 deletions crates/backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Server {
}

impl Server {
#[must_use]
pub fn new(federation_config: &FederationConfig<AppData>) -> Self {
Self {
federation_config: federation_config.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/nodeinfo/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use activitypub_federation::config::Data;
use axum::{debug_handler, Json};
use hatsu_utils::{AppData, AppError};

use crate::schema::*;
use crate::schema::NodeInfo;

/// NodeInfo schema version 2.0.
///
Expand Down
6 changes: 3 additions & 3 deletions crates/nodeinfo/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// NodeInfo schema.
/// `NodeInfo` schema.
///
/// <https://nodeinfo.diaspora.software/schema.html>
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
Expand Down Expand Up @@ -37,8 +37,8 @@ impl NodeInfo {
protocols: vec![String::from("activitypub")],
services: NodeInfoServices::new(),
open_registrations: false,
usage: NodeInfoUsage::new(&data).await?,
metadata: NodeInfoMetadata::new(&data),
usage: NodeInfoUsage::new(data).await?,
metadata: NodeInfoMetadata::new(data),
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Scheduler {
}

impl Scheduler {
#[must_use]
pub fn new(federation_config: &FederationConfig<AppData>) -> Self {
Self {
federation_config: federation_config.clone(),
Expand Down
1 change: 1 addition & 0 deletions crates/utils/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct AppEnv {
}

impl AppEnv {
#[must_use]
pub fn init() -> Self {
Self {
hatsu_database_url: env::var("HATSU_DATABASE_URL")
Expand Down
10 changes: 5 additions & 5 deletions crates/utils/src/user/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ pub struct Feed {
impl Feed {
/// 从网站获取 Feed 链接
pub async fn get_site_feed(domain: String) -> Result<Self, AppError> {
let response = reqwest::get(format!("https://{}", &domain)).await?;
let text = response.text().await?;
let document = Html::parse_document(&text);
let head = Selector::parse("head").expect("valid selector");

fn feed_auto_discovery(head: &ElementRef, domain: &str, kind: &str) -> Option<Url> {
head.select(
&Selector::parse(&format!("link[rel=\"alternate\"][type=\"{kind}\"]"))
Expand All @@ -36,6 +31,11 @@ impl Feed {
})
}

let response = reqwest::get(format!("https://{}", &domain)).await?;
let text = response.text().await?;
let document = Html::parse_document(&text);
let head = Selector::parse("head").expect("valid selector");

document.select(&head).next().map_or_else(
|| {
Err(AppError::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/well_known/src/entities/nodeinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct NodeInfoWellKnownLink {
impl NodeInfoWellKnownLink {
pub fn new(data: &Data<AppData>, version: &str) -> Self {
Self {
rel: format!("http://nodeinfo.diaspora.software/ns/schema/{}", version),
rel: format!("http://nodeinfo.diaspora.software/ns/schema/{version}"),
href: format!("https://{}/nodeinfo/{}.json", data.domain(), version),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/well_known/src/entities/webfinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Serialize;
use url::Url;
use utoipa::ToSchema;

/// impl ToSchema for Webfinger
/// impl `ToSchema` for `Webfinger`
#[derive(Serialize, ToSchema)]
pub struct WebfingerSchema {
/// The actor which is described here, for example `acct:[email protected]`
Expand All @@ -19,7 +19,7 @@ pub struct WebfingerSchema {
pub properties: HashMap<Url, String>,
}

/// impl ToSchema for WebfingerLink
/// impl `ToSchema`` for `WebfingerLink`
#[derive(Serialize, ToSchema)]
pub struct WebfingerSchemaLink {
/// Relationship of the link, such as `self` or `http://webfinger.net/rel/profile-page`
Expand Down

0 comments on commit 8f288fc

Please sign in to comment.