-
-
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.
introduce fetcher and resolver traits
- Loading branch information
Showing
24 changed files
with
120 additions
and
60 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use kitsune_db::model::{account::Account, custom_emoji::CustomEmoji, post::Post}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::future::Future; | ||
use typed_builder::TypedBuilder; | ||
|
||
#[derive(Clone, Debug, TypedBuilder)] | ||
/// Options passed to the fetcher | ||
pub struct AccountFetchOptions<'a> { | ||
/// Prefetched WebFinger `acct` URI | ||
#[builder(default, setter(strip_option))] | ||
pub acct: Option<(&'a str, &'a str)>, | ||
|
||
/// Refetch the ActivityPub entity | ||
/// | ||
/// This is mainly used to refresh possibly stale actors | ||
/// | ||
/// Default: false | ||
#[builder(default = false)] | ||
pub refetch: bool, | ||
|
||
/// URL of the ActivityPub entity | ||
pub url: &'a str, | ||
} | ||
|
||
impl<'a> From<&'a str> for AccountFetchOptions<'a> { | ||
fn from(value: &'a str) -> Self { | ||
Self::builder().url(value).build() | ||
} | ||
} | ||
|
||
/// Description of a resolved account | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct AccountResource { | ||
/// The `self` link (the account's URI) | ||
pub uri: String, | ||
/// The username part of the canonical `acct:` URI | ||
pub username: String, | ||
/// The host component of the canonical `acct:` URI | ||
pub domain: String, | ||
} | ||
|
||
pub trait Fetcher { | ||
type Error; | ||
|
||
fn fetch_account( | ||
&self, | ||
opts: AccountFetchOptions<'_>, | ||
) -> impl Future<Output = Result<Account, Self::Error>> + Send; | ||
|
||
fn fetch_emoji( | ||
&self, | ||
url: &str, | ||
) -> impl Future<Output = Result<CustomEmoji, Self::Error>> + Send; | ||
|
||
fn fetch_post(&self, url: &str) -> impl Future<Output = Result<Post, Self::Error>> + Send; | ||
} | ||
|
||
pub trait Resolver { | ||
type Error; | ||
|
||
fn resolve_account( | ||
&self, | ||
username: &str, | ||
domain: &str, | ||
) -> impl Future<Output = Result<Option<AccountResource>, Self::Error>> + Send; | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.