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