Return empty array instead of error if search for remote profile fails
This commit is contained in:
parent
aa1ef71857
commit
5cd79eb9b6
3 changed files with 14 additions and 10 deletions
|
@ -67,6 +67,7 @@ pub async fn fetch_profile(
|
||||||
let webfinger_data = client.get(&webfinger_url)
|
let webfinger_data = client.get(&webfinger_url)
|
||||||
.query(&[("resource", webfinger_account_uri)])
|
.query(&[("resource", webfinger_account_uri)])
|
||||||
.send().await?
|
.send().await?
|
||||||
|
.error_for_status()?
|
||||||
.text().await?;
|
.text().await?;
|
||||||
let jrd: JsonResourceDescriptor = serde_json::from_str(&webfinger_data)?;
|
let jrd: JsonResourceDescriptor = serde_json::from_str(&webfinger_data)?;
|
||||||
let link = jrd.links.iter()
|
let link = jrd.links.iter()
|
||||||
|
|
|
@ -33,17 +33,19 @@ async fn search_profiles(
|
||||||
if profiles.len() == 0 && instance.is_some() {
|
if profiles.len() == 0 && instance.is_some() {
|
||||||
let instance_uri = instance.unwrap();
|
let instance_uri = instance.unwrap();
|
||||||
let media_dir = config.media_dir();
|
let media_dir = config.media_dir();
|
||||||
let profile_data = fetch_profile(&username, &instance_uri, &media_dir).await
|
match fetch_profile(&username, &instance_uri, &media_dir).await {
|
||||||
.map_err(|err| {
|
Ok(profile_data) => {
|
||||||
|
let profile = create_profile(db_client, &profile_data).await?;
|
||||||
|
log::info!(
|
||||||
|
"imported profile '{}'",
|
||||||
|
profile.acct,
|
||||||
|
);
|
||||||
|
profiles.push(profile);
|
||||||
|
},
|
||||||
|
Err(err) => {
|
||||||
log::warn!("{}", err);
|
log::warn!("{}", err);
|
||||||
HttpError::NotFoundError("remote profile")
|
},
|
||||||
})?;
|
}
|
||||||
let profile = create_profile(db_client, &profile_data).await?;
|
|
||||||
log::info!(
|
|
||||||
"imported profile '{}'",
|
|
||||||
profile.acct,
|
|
||||||
);
|
|
||||||
profiles.push(profile);
|
|
||||||
}
|
}
|
||||||
Ok(profiles)
|
Ok(profiles)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/// https://docs.joinmastodon.org/methods/search/
|
||||||
use actix_web::{get, web, HttpResponse, Scope};
|
use actix_web::{get, web, HttpResponse, Scope};
|
||||||
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
use actix_web_httpauth::extractors::bearer::BearerAuth;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue