Rename fetch_attachment to fetch_file

This commit is contained in:
silverpill 2022-05-02 00:01:57 +00:00
parent fd067713d7
commit b9ae2f07e7
2 changed files with 14 additions and 14 deletions

View file

@ -73,13 +73,23 @@ async fn send_request(
Ok(data)
}
pub async fn fetch_file(
url: &str,
output_dir: &Path,
) -> Result<(String, Option<String>), FetchError> {
let response = reqwest::get(url).await?;
let file_data = response.bytes().await?;
let (file_name, media_type) = save_file(file_data.to_vec(), output_dir)?;
Ok((file_name, media_type))
}
pub async fn fetch_avatar_and_banner(
actor: &Actor,
media_dir: &Path,
) -> Result<(Option<String>, Option<String>), FetchError> {
let avatar = match &actor.icon {
Some(icon) => {
let (file_name, _) = fetch_attachment(
let (file_name, _) = fetch_file(
&icon.url,
media_dir,
).await?;
@ -89,7 +99,7 @@ pub async fn fetch_avatar_and_banner(
};
let banner = match &actor.image {
Some(image) => {
let (file_name, _) = fetch_attachment(
let (file_name, _) = fetch_file(
&image.url,
media_dir,
).await?;
@ -166,16 +176,6 @@ pub async fn fetch_profile_by_actor_id(
Ok(profile_data)
}
pub async fn fetch_attachment(
url: &str,
output_dir: &Path,
) -> Result<(String, Option<String>), FetchError> {
let response = reqwest::get(url).await?;
let file_data = response.bytes().await?;
let (file_name, media_type) = save_file(file_data.to_vec(), output_dir)?;
Ok((file_name, media_type))
}
pub async fn fetch_object(
instance: &Instance,
object_url: &str,

View file

@ -50,7 +50,7 @@ use super::actor::Actor;
use super::deliverer::deliver_activity;
use super::fetcher::fetchers::{
fetch_avatar_and_banner,
fetch_attachment,
fetch_file,
fetch_object,
};
use super::fetcher::helpers::{
@ -286,7 +286,7 @@ pub async fn import_post(
};
let attachment_url = attachment.url
.ok_or(ValidationError("attachment URL is missing"))?;
let (file_name, media_type) = fetch_attachment(&attachment_url, &output_dir).await
let (file_name, media_type) = fetch_file(&attachment_url, &output_dir).await
.map_err(|_| ValidationError("failed to fetch attachment"))?;
log::info!("downloaded attachment {}", attachment_url);
downloaded.push((