-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
108 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "kitsune-federation" | ||
edition.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
derive_more = { version = "1.0.0-beta.6", features = ["from"] } | ||
futures-util = "0.3.29" | ||
kitsune-activitypub = { path = "../kitsune-activitypub" } | ||
kitsune-core = { path = "../kitsune-core" } | ||
kitsune-db = { path = "../kitsune-db" } | ||
kitsune-webfinger = { path = "../kitsune-webfinger" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use derive_more::From; | ||
use futures_util::{future::BoxFuture, FutureExt, TryFutureExt}; | ||
use kitsune_activitypub::{Deliverer as ActivityPubDeliverer, Fetcher as ActivityPubFetcher}; | ||
use kitsune_core::{ | ||
error::BoxError, | ||
traits::{deliverer, fetcher::AccountFetchOptions, Deliverer, Fetcher}, | ||
}; | ||
use kitsune_db::model::{account::Account, custom_emoji::CustomEmoji, post::Post}; | ||
use kitsune_webfinger::Webfinger; | ||
use std::sync::Arc; | ||
|
||
pub struct Federator { | ||
pub deliverer: Vec<AnyDeliverer>, | ||
pub fetcher: Vec<AnyFetcher>, | ||
} | ||
|
||
#[derive(Clone, From)] | ||
pub enum AnyDeliverer { | ||
ActivityPub(Arc<ActivityPubDeliverer>), | ||
} | ||
|
||
impl Deliverer for AnyDeliverer { | ||
type Error = BoxError; | ||
|
||
fn deliver(&self, action: deliverer::Action) -> BoxFuture<'_, Result<(), Self::Error>> { | ||
match self { | ||
Self::ActivityPub(deliverer) => deliverer.deliver(action).map_err(Into::into).boxed(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, From)] | ||
pub enum AnyFetcher { | ||
ActivityPub(ActivityPubFetcher<Webfinger>), | ||
} | ||
|
||
impl Fetcher for AnyFetcher { | ||
type Error = BoxError; | ||
|
||
async fn fetch_account(&self, opts: AccountFetchOptions<'_>) -> Result<Account, Self::Error> { | ||
match self { | ||
Self::ActivityPub(fetcher) => fetcher.fetch_account(opts).await.map_err(Into::into), | ||
} | ||
} | ||
|
||
async fn fetch_emoji(&self, url: &str) -> Result<CustomEmoji, Self::Error> { | ||
match self { | ||
Self::ActivityPub(fetcher) => fetcher.fetch_emoji(url).await.map_err(Into::into), | ||
} | ||
} | ||
|
||
async fn fetch_post(&self, url: &str) -> Result<Post, Self::Error> { | ||
match self { | ||
Self::ActivityPub(fetcher) => fetcher.fetch_post(url).await.map_err(Into::into), | ||
} | ||
} | ||
} | ||
|
||
fn prepare_activitypub() -> (ActivityPubFetcher<Webfinger>, Arc<ActivityPubDeliverer>) { | ||
todo!(); | ||
} | ||
|
||
pub fn prepare_federator() -> Federator { | ||
let (fetcher, deliverer) = prepare_activitypub(); | ||
|
||
Federator { | ||
deliverer: vec![deliverer.into()], | ||
fetcher: vec![fetcher.into()], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters