fix: infer document type from mimetype
This commit is contained in:
parent
44690b3637
commit
6f0026a818
1 changed files with 17 additions and 1 deletions
|
@ -272,11 +272,27 @@ impl AP {
|
|||
if !matches!(t, apb::BaseType::Object(apb::ObjectType::Document(_))) {
|
||||
return Err(NormalizerError::WrongType(apb::BaseType::Object(apb::ObjectType::Document(apb::DocumentType::Document)), t));
|
||||
}
|
||||
|
||||
// if they gave us just url+mimetype, try detecting document type from mimetype
|
||||
let mut document_type = document.document_type().ok();
|
||||
if document_type.is_none() {
|
||||
if let Ok(media_type) = document.media_type() {
|
||||
if let Some((t, _mime)) = media_type.split_once('/') {
|
||||
document_type = match t {
|
||||
"audio" => Some(apb::DocumentType::Audio),
|
||||
"image" => Some(apb::DocumentType::Image),
|
||||
"video" => Some(apb::DocumentType::Video),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(crate::model::attachment::Model {
|
||||
internal: 0,
|
||||
url: document.url().id().unwrap_or_default(),
|
||||
object: parent,
|
||||
document_type: document.as_document().map_or(apb::DocumentType::Document, |x| x.document_type().unwrap_or(apb::DocumentType::Page)),
|
||||
document_type: document_type.unwrap_or(apb::DocumentType::Page),
|
||||
name: document.name().ok(),
|
||||
media_type: document.media_type().unwrap_or("link".to_string()),
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue