diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 1c2ed26..656ff01 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -145,9 +145,30 @@ paths: type: string nullable: true note: - description: The account bio. + description: The account bio (markdown). type: string nullable: true + avatar: + description: Avatar image encoded as base64. + type: string + nullable: true + header: + description: Header image encoded as base64. + type: string + nullable: true + fields_attributes: + description: The profile fields to be set. + type: array + nullable: true + items: + type: object + properties: + name: + description: Name of the field. + type: string + value: + description: Value of the field (markdown). + type: string responses: 200: description: Successful operation. diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index 903aab3..0ec3810 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -203,14 +203,19 @@ impl AccountCreateData { } } +#[derive(Deserialize)] +struct AccountFieldSource { + name: String, + value: String, +} + #[derive(Deserialize)] pub struct AccountUpdateData { - pub display_name: Option, - pub note: Option, - pub note_source: Option, - pub avatar: Option, - pub header: Option, - pub fields_attributes: Option>, + display_name: Option, + note: Option, + avatar: Option, + header: Option, + fields_attributes: Option>, } fn process_b64_image_field_value( @@ -246,8 +251,8 @@ impl AccountUpdateData { current_payment_options: &[PaymentOption], media_dir: &Path, ) -> Result { - let maybe_bio = if let Some(ref note_source) = self.note_source { - let bio = markdown_basic_to_html(note_source) + let maybe_bio = if let Some(ref bio_source) = self.note { + let bio = markdown_basic_to_html(bio_source) .map_err(|_| ValidationError("invalid markdown"))?; Some(bio) } else { @@ -261,17 +266,21 @@ impl AccountUpdateData { )?; let identity_proofs = current_identity_proofs.to_vec(); let payment_options = current_payment_options.to_vec(); - let mut extra_fields = self.fields_attributes.unwrap_or(vec![]); - for extra_field in extra_fields.iter_mut() { - let value_source = extra_field.value_source.as_ref() - .ok_or(ValidationError("missing value source"))?; - extra_field.value = markdown_basic_to_html(value_source) + let mut extra_fields = vec![]; + for field_source in self.fields_attributes.unwrap_or(vec![]) { + let value = markdown_basic_to_html(&field_source.value) .map_err(|_| ValidationError("invalid markdown"))?; + let extra_field = ExtraField { + name: field_source.name, + value: value, + value_source: Some(field_source.value), + }; + extra_fields.push(extra_field); }; let profile_data = ProfileUpdateData { display_name: self.display_name, bio: maybe_bio, - bio_source: self.note_source, + bio_source: self.note, avatar, banner, identity_proofs,