Rewrite fetch_profile to accept ActorAddress object
This commit is contained in:
parent
b05a8b2757
commit
5c0e6b0b0c
3 changed files with 15 additions and 9 deletions
|
@ -208,13 +208,19 @@ pub struct ActorAddress {
|
||||||
pub is_local: bool,
|
pub is_local: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToString for ActorAddress {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
format!("{}@{}", self.username, self.instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActorAddress {
|
impl ActorAddress {
|
||||||
/// Returns acct string, as used in Mastodon
|
/// Returns acct string, as used in Mastodon
|
||||||
pub fn acct(&self) -> String {
|
pub fn acct(&self) -> String {
|
||||||
if self.is_local {
|
if self.is_local {
|
||||||
self.username.clone()
|
self.username.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("{}@{}", self.username, self.instance)
|
self.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use reqwest::Method;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use crate::activitypub::activity::Object;
|
use crate::activitypub::activity::Object;
|
||||||
use crate::activitypub::actor::Actor;
|
use crate::activitypub::actor::{Actor, ActorAddress};
|
||||||
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
|
use crate::activitypub::constants::ACTIVITY_CONTENT_TYPE;
|
||||||
use crate::config::Instance;
|
use crate::config::Instance;
|
||||||
use crate::http_signatures::create::{create_http_signature, SignatureError};
|
use crate::http_signatures::create::{create_http_signature, SignatureError};
|
||||||
|
@ -112,14 +112,15 @@ pub async fn fetch_avatar_and_banner(
|
||||||
|
|
||||||
pub async fn fetch_profile(
|
pub async fn fetch_profile(
|
||||||
instance: &Instance,
|
instance: &Instance,
|
||||||
username: &str,
|
actor_address: &ActorAddress,
|
||||||
actor_host: &str,
|
|
||||||
media_dir: &Path,
|
media_dir: &Path,
|
||||||
) -> Result<ProfileCreateData, FetchError> {
|
) -> Result<ProfileCreateData, FetchError> {
|
||||||
let actor_address = format!("{}@{}", &username, &actor_host);
|
let webfinger_account_uri = format!("acct:{}", actor_address.to_string());
|
||||||
let webfinger_account_uri = format!("acct:{}", actor_address);
|
|
||||||
// TOOD: support http
|
// TOOD: support http
|
||||||
let webfinger_url = format!("https://{}/.well-known/webfinger", actor_host);
|
let webfinger_url = format!(
|
||||||
|
"https://{}/.well-known/webfinger",
|
||||||
|
actor_address.instance,
|
||||||
|
);
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let mut request_builder = client.get(&webfinger_url);
|
let mut request_builder = client.get(&webfinger_url);
|
||||||
if !instance.is_private {
|
if !instance.is_private {
|
||||||
|
|
|
@ -94,8 +94,7 @@ pub async fn import_profile_by_actor_address(
|
||||||
};
|
};
|
||||||
let mut profile_data = fetch_profile(
|
let mut profile_data = fetch_profile(
|
||||||
instance,
|
instance,
|
||||||
&actor_address.username,
|
actor_address,
|
||||||
&actor_address.instance,
|
|
||||||
media_dir,
|
media_dir,
|
||||||
).await?;
|
).await?;
|
||||||
if profile_data.acct != actor_address.acct() {
|
if profile_data.acct != actor_address.acct() {
|
||||||
|
|
Loading…
Reference in a new issue