fix: lint code

This commit is contained in:
藍+85CD 2024-07-26 20:51:48 +08:00
parent 1d877348ed
commit 9b2df05977
No known key found for this signature in database
GPG key ID: BCB0111111111111
14 changed files with 26 additions and 27 deletions

View file

@ -31,7 +31,7 @@ pub struct CreatePost {
impl CreatePost { impl CreatePost {
pub async fn send(note: Note, inbox: Url, data: &Data<DatabaseHandle>) -> Result<(), Error> { pub async fn send(note: Note, inbox: Url, data: &Data<DatabaseHandle>) -> Result<(), Error> {
print!("Sending reply to {}", &note.attributed_to); print!("Sending reply to {}", &note.attributed_to);
let create = CreatePost { let create = Self {
actor: note.attributed_to.clone(), actor: note.attributed_to.clone(),
to: note.to.clone(), to: note.to.clone(),
object: note, object: note,

View file

@ -15,6 +15,6 @@ where
T: Into<anyhow::Error>, T: Into<anyhow::Error>,
{ {
fn from(t: T) -> Self { fn from(t: T) -> Self {
Error(t.into()) Self(t.into())
} }
} }

View file

@ -35,11 +35,11 @@ pub enum PersonAcceptedActivities {
} }
impl DbUser { impl DbUser {
pub fn new(hostname: &str, name: &str) -> Result<DbUser, Error> { pub fn new(hostname: &str, name: &str) -> Result<Self, Error> {
let ap_id = Url::parse(&format!("https://{}/{}", hostname, &name))?.into(); let ap_id = Url::parse(&format!("https://{}/{}", hostname, &name))?.into();
let inbox = Url::parse(&format!("https://{}/{}/inbox", hostname, &name))?; let inbox = Url::parse(&format!("https://{}/{}/inbox", hostname, &name))?;
let keypair = generate_actor_keypair()?; let keypair = generate_actor_keypair()?;
Ok(DbUser { Ok(Self {
name: name.to_string(), name: name.to_string(),
ap_id, ap_id,
inbox, inbox,
@ -108,7 +108,7 @@ impl Object for DbUser {
json: Self::Kind, json: Self::Kind,
_data: &Data<Self::DataType>, _data: &Data<Self::DataType>,
) -> Result<Self, Self::Error> { ) -> Result<Self, Self::Error> {
Ok(DbUser { Ok(Self {
name: json.preferred_username, name: json.preferred_username,
ap_id: json.id, ap_id: json.id,
inbox: json.inbox, inbox: json.inbox,

View file

@ -84,7 +84,7 @@ impl Object for DbPost {
&json.content, &json.id &json.content, &json.id
); );
let creator = json.attributed_to.dereference(data).await?; let creator = json.attributed_to.dereference(data).await?;
let post = DbPost { let post = Self {
text: json.content, text: json.content,
ap_id: json.id.clone(), ap_id: json.id.clone(),
creator: json.attributed_to.clone(), creator: json.attributed_to.clone(),

View file

@ -9,5 +9,5 @@ pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
.take(7) .take(7)
.map(char::from) .map(char::from)
.collect(); .collect();
Url::parse(&format!("https://{}/objects/{}", domain, id)) Url::parse(&format!("https://{domain}/objects/{id}"))
} }

View file

@ -19,8 +19,8 @@ pub struct Accept {
} }
impl Accept { impl Accept {
pub fn new(actor: ObjectId<DbUser>, object: Follow, id: Url) -> Accept { pub fn new(actor: ObjectId<DbUser>, object: Follow, id: Url) -> Self {
Accept { Self {
actor, actor,
object, object,
kind: Default::default(), kind: Default::default(),

View file

@ -26,8 +26,8 @@ pub struct CreatePost {
} }
impl CreatePost { impl CreatePost {
pub fn new(note: Note, id: Url) -> CreatePost { pub fn new(note: Note, id: Url) -> Self {
CreatePost { Self {
actor: note.attributed_to.clone(), actor: note.attributed_to.clone(),
to: note.to.clone(), to: note.to.clone(),
object: note, object: note,

View file

@ -24,8 +24,8 @@ pub struct Follow {
} }
impl Follow { impl Follow {
pub fn new(actor: ObjectId<DbUser>, object: ObjectId<DbUser>, id: Url) -> Follow { pub fn new(actor: ObjectId<DbUser>, object: ObjectId<DbUser>, id: Url) -> Self {
Follow { Self {
actor, actor,
object, object,
kind: Default::default(), kind: Default::default(),

View file

@ -15,6 +15,6 @@ where
T: Into<anyhow::Error>, T: Into<anyhow::Error>,
{ {
fn from(t: T) -> Self { fn from(t: T) -> Self {
Error(t.into()) Self(t.into())
} }
} }

View file

@ -16,7 +16,7 @@ pub async fn new_instance(
name: String, name: String,
) -> Result<FederationConfig<DatabaseHandle>, Error> { ) -> Result<FederationConfig<DatabaseHandle>, Error> {
let mut system_user = DbUser::new(hostname, "system".into())?; let mut system_user = DbUser::new(hostname, "system".into())?;
system_user.ap_id = Url::parse(&format!("http://{}/", hostname))?.into(); system_user.ap_id = Url::parse(&format!("http://{hostname}/"))?.into();
let local_user = DbUser::new(hostname, name)?; let local_user = DbUser::new(hostname, name)?;
let database = Arc::new(Database { let database = Arc::new(Database {
@ -70,7 +70,7 @@ impl FromStr for Webserver {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s { Ok(match s {
"axum" => Webserver::Axum, "axum" => Self::Axum,
_ => panic!("Invalid webserver parameter, must be either `axum` or `actix-web`"), _ => panic!("Invalid webserver parameter, must be either `axum` or `actix-web`"),
}) })
} }

View file

@ -29,8 +29,7 @@ async fn main() -> Result<(), Error> {
info!("Start with parameter `axum` or `actix-web` to select the webserver"); info!("Start with parameter `axum` or `actix-web` to select the webserver");
let webserver = args() let webserver = args()
.nth(1) .nth(1)
.map(|arg| Webserver::from_str(&arg).unwrap()) .map_or(Webserver::Axum, |arg| Webserver::from_str(&arg).unwrap());
.unwrap_or(Webserver::Axum);
let alpha = new_instance("localhost:8001", "alpha".to_string()).await?; let alpha = new_instance("localhost:8001", "alpha".to_string()).await?;
let beta = new_instance("localhost:8002", "beta".to_string()).await?; let beta = new_instance("localhost:8002", "beta".to_string()).await?;

View file

@ -45,11 +45,11 @@ pub enum PersonAcceptedActivities {
} }
impl DbUser { impl DbUser {
pub fn new(hostname: &str, name: String) -> Result<DbUser, Error> { pub fn new(hostname: &str, name: String) -> Result<Self, Error> {
let ap_id = Url::parse(&format!("http://{}/{}", hostname, &name))?.into(); let ap_id = Url::parse(&format!("http://{}/{}", hostname, &name))?.into();
let inbox = Url::parse(&format!("http://{}/{}/inbox", hostname, &name))?; let inbox = Url::parse(&format!("http://{}/{}/inbox", hostname, &name))?;
let keypair = generate_actor_keypair()?; let keypair = generate_actor_keypair()?;
Ok(DbUser { Ok(Self {
name, name,
ap_id, ap_id,
inbox, inbox,
@ -83,7 +83,7 @@ impl DbUser {
} }
pub async fn follow(&self, other: &str, data: &Data<DatabaseHandle>) -> Result<(), Error> { pub async fn follow(&self, other: &str, data: &Data<DatabaseHandle>) -> Result<(), Error> {
let other: DbUser = webfinger_resolve_actor(other, data).await?; let other: Self = webfinger_resolve_actor(other, data).await?;
let id = generate_object_id(data.domain())?; let id = generate_object_id(data.domain())?;
let follow = Follow::new(self.ap_id.clone(), other.ap_id.clone(), id.clone()); let follow = Follow::new(self.ap_id.clone(), other.ap_id.clone(), id.clone());
self.send(follow, vec![other.shared_inbox_or_inbox()], false, data) self.send(follow, vec![other.shared_inbox_or_inbox()], false, data)
@ -96,7 +96,7 @@ impl DbUser {
let create = CreatePost::new(post.into_json(data).await?, id.clone()); let create = CreatePost::new(post.into_json(data).await?, id.clone());
let mut inboxes = vec![]; let mut inboxes = vec![];
for f in self.followers.clone() { for f in self.followers.clone() {
let user: DbUser = ObjectId::from(f).dereference(data).await?; let user: Self = ObjectId::from(f).dereference(data).await?;
inboxes.push(user.shared_inbox_or_inbox()); inboxes.push(user.shared_inbox_or_inbox());
} }
self.send(create, inboxes, true, data).await?; self.send(create, inboxes, true, data).await?;
@ -170,7 +170,7 @@ impl Object for DbUser {
} }
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> { async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
let user = DbUser { let user = Self {
name: json.preferred_username, name: json.preferred_username,
ap_id: json.id, ap_id: json.id,
inbox: json.inbox, inbox: json.inbox,

View file

@ -18,9 +18,9 @@ pub struct DbPost {
} }
impl DbPost { impl DbPost {
pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<DbPost, Error> { pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<Self, Error> {
let ap_id = generate_object_id(creator.inner().domain().unwrap())?.into(); let ap_id = generate_object_id(creator.inner().domain().unwrap())?.into();
Ok(DbPost { Ok(Self {
text, text,
ap_id, ap_id,
creator, creator,
@ -80,7 +80,7 @@ impl Object for DbPost {
} }
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> { async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
let post = DbPost { let post = Self {
text: json.content, text: json.content,
ap_id: json.id, ap_id: json.id,
creator: json.attributed_to, creator: json.attributed_to,

View file

@ -9,5 +9,5 @@ pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
.take(7) .take(7)
.map(char::from) .map(char::from)
.collect(); .collect();
Url::parse(&format!("http://{}/objects/{}", domain, id)) Url::parse(&format!("http://{domain}/objects/{id}"))
} }