Save media types of uploaded avatar and banner images
This commit is contained in:
parent
682cf09835
commit
44ce9a73a2
5 changed files with 25 additions and 5 deletions
|
@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Implemented activity delivery queue.
|
||||
- Started to keep track of unreachable actors.
|
||||
- Added `configuration` object to response of `/api/v1/instance` endpoint.
|
||||
- Save media types of uploaded avatar and banner images.
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -22,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
### Deprecated
|
||||
|
||||
- Deprecated `post_character_limit` property in `/api/v1/instance` response.
|
||||
- Avatar and banner uploads without media type via `/api/v1/accounts/update_credentials`.
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -152,10 +152,18 @@ paths:
|
|||
description: Avatar image encoded as base64.
|
||||
type: string
|
||||
nullable: true
|
||||
avatar_media_type:
|
||||
description: The media type of avatar image.
|
||||
type: string
|
||||
nullable: true
|
||||
header:
|
||||
description: Header image encoded as base64.
|
||||
type: string
|
||||
nullable: true
|
||||
header_media_type:
|
||||
description: The media type of header image.
|
||||
type: string
|
||||
nullable: true
|
||||
fields_attributes:
|
||||
description: The profile fields to be set.
|
||||
type: array
|
||||
|
|
|
@ -28,7 +28,7 @@ async fn fetch_actor_images(
|
|||
let maybe_avatar = if let Some(icon) = &actor.icon {
|
||||
match fetch_file(instance, &icon.url, media_dir).await {
|
||||
Ok((file_name, _)) => {
|
||||
let image = ProfileImage { file_name };
|
||||
let image = ProfileImage { file_name, media_type: None };
|
||||
Some(image)
|
||||
},
|
||||
Err(error) => {
|
||||
|
@ -42,7 +42,7 @@ async fn fetch_actor_images(
|
|||
let maybe_banner = if let Some(image) = &actor.image {
|
||||
match fetch_file(instance, &image.url, media_dir).await {
|
||||
Ok((file_name, _)) => {
|
||||
let image = ProfileImage { file_name };
|
||||
let image = ProfileImage { file_name, media_type: None };
|
||||
Some(image)
|
||||
},
|
||||
Err(error) => {
|
||||
|
|
|
@ -214,12 +214,15 @@ pub struct AccountUpdateData {
|
|||
display_name: Option<String>,
|
||||
note: Option<String>,
|
||||
avatar: Option<String>,
|
||||
avatar_media_type: Option<String>,
|
||||
header: Option<String>,
|
||||
header_media_type: Option<String>,
|
||||
fields_attributes: Option<Vec<AccountFieldSource>>,
|
||||
}
|
||||
|
||||
fn process_b64_image_field_value(
|
||||
form_value: Option<String>,
|
||||
form_media_type: Option<String>,
|
||||
db_value: Option<ProfileImage>,
|
||||
output_dir: &Path,
|
||||
) -> Result<Option<ProfileImage>, UploadError> {
|
||||
|
@ -230,13 +233,16 @@ fn process_b64_image_field_value(
|
|||
None
|
||||
} else {
|
||||
// Decode and save file
|
||||
let (file_name, _) = save_b64_file(
|
||||
let (file_name, media_type) = save_b64_file(
|
||||
&b64_data,
|
||||
None,
|
||||
form_media_type,
|
||||
output_dir,
|
||||
Some("image/"),
|
||||
)?;
|
||||
let image = ProfileImage { file_name };
|
||||
let image = ProfileImage {
|
||||
file_name,
|
||||
media_type: Some(media_type),
|
||||
};
|
||||
Some(image)
|
||||
}
|
||||
},
|
||||
|
@ -261,11 +267,13 @@ impl AccountUpdateData {
|
|||
};
|
||||
let avatar = process_b64_image_field_value(
|
||||
self.avatar,
|
||||
self.avatar_media_type,
|
||||
profile.avatar.clone(),
|
||||
media_dir,
|
||||
)?;
|
||||
let banner = process_b64_image_field_value(
|
||||
self.header,
|
||||
self.header_media_type,
|
||||
profile.banner.clone(),
|
||||
media_dir,
|
||||
)?;
|
||||
|
@ -488,6 +496,7 @@ mod tests {
|
|||
let profile = DbActorProfile {
|
||||
avatar: Some(ProfileImage {
|
||||
file_name: "test".to_string(),
|
||||
media_type: None,
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
@ -33,6 +33,7 @@ use super::validators::{
|
|||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct ProfileImage {
|
||||
pub file_name: String,
|
||||
pub media_type: Option<String>,
|
||||
}
|
||||
|
||||
json_from_sql!(ProfileImage);
|
||||
|
|
Loading…
Reference in a new issue