Stop accepting pre-rendered bio/fields
This commit is contained in:
parent
a23a555a05
commit
81c0f5e2bd
2 changed files with 45 additions and 15 deletions
|
@ -145,9 +145,30 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
nullable: true
|
nullable: true
|
||||||
note:
|
note:
|
||||||
description: The account bio.
|
description: The account bio (markdown).
|
||||||
type: string
|
type: string
|
||||||
nullable: true
|
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:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Successful operation.
|
description: Successful operation.
|
||||||
|
|
|
@ -203,14 +203,19 @@ impl AccountCreateData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct AccountFieldSource {
|
||||||
|
name: String,
|
||||||
|
value: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct AccountUpdateData {
|
pub struct AccountUpdateData {
|
||||||
pub display_name: Option<String>,
|
display_name: Option<String>,
|
||||||
pub note: Option<String>,
|
note: Option<String>,
|
||||||
pub note_source: Option<String>,
|
avatar: Option<String>,
|
||||||
pub avatar: Option<String>,
|
header: Option<String>,
|
||||||
pub header: Option<String>,
|
fields_attributes: Option<Vec<AccountFieldSource>>,
|
||||||
pub fields_attributes: Option<Vec<ExtraField>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_b64_image_field_value(
|
fn process_b64_image_field_value(
|
||||||
|
@ -246,8 +251,8 @@ impl AccountUpdateData {
|
||||||
current_payment_options: &[PaymentOption],
|
current_payment_options: &[PaymentOption],
|
||||||
media_dir: &Path,
|
media_dir: &Path,
|
||||||
) -> Result<ProfileUpdateData, HttpError> {
|
) -> Result<ProfileUpdateData, HttpError> {
|
||||||
let maybe_bio = if let Some(ref note_source) = self.note_source {
|
let maybe_bio = if let Some(ref bio_source) = self.note {
|
||||||
let bio = markdown_basic_to_html(note_source)
|
let bio = markdown_basic_to_html(bio_source)
|
||||||
.map_err(|_| ValidationError("invalid markdown"))?;
|
.map_err(|_| ValidationError("invalid markdown"))?;
|
||||||
Some(bio)
|
Some(bio)
|
||||||
} else {
|
} else {
|
||||||
|
@ -261,17 +266,21 @@ impl AccountUpdateData {
|
||||||
)?;
|
)?;
|
||||||
let identity_proofs = current_identity_proofs.to_vec();
|
let identity_proofs = current_identity_proofs.to_vec();
|
||||||
let payment_options = current_payment_options.to_vec();
|
let payment_options = current_payment_options.to_vec();
|
||||||
let mut extra_fields = self.fields_attributes.unwrap_or(vec![]);
|
let mut extra_fields = vec![];
|
||||||
for extra_field in extra_fields.iter_mut() {
|
for field_source in self.fields_attributes.unwrap_or(vec![]) {
|
||||||
let value_source = extra_field.value_source.as_ref()
|
let value = markdown_basic_to_html(&field_source.value)
|
||||||
.ok_or(ValidationError("missing value source"))?;
|
|
||||||
extra_field.value = markdown_basic_to_html(value_source)
|
|
||||||
.map_err(|_| ValidationError("invalid markdown"))?;
|
.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 {
|
let profile_data = ProfileUpdateData {
|
||||||
display_name: self.display_name,
|
display_name: self.display_name,
|
||||||
bio: maybe_bio,
|
bio: maybe_bio,
|
||||||
bio_source: self.note_source,
|
bio_source: self.note,
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
identity_proofs,
|
identity_proofs,
|
||||||
|
|
Loading…
Reference in a new issue