fix: accept link attachments

kind of hacky way but should work
This commit is contained in:
əlemi 2024-05-08 02:26:18 +02:00
parent 237917c8d8
commit 488cac9703
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,4 +1,4 @@
use apb::{DocumentMut, ObjectMut}; use apb::{Document, DocumentMut, Link, Object, ObjectMut};
use sea_orm::{entity::prelude::*, Set}; use sea_orm::{entity::prelude::*, Set};
use crate::routes::activitypub::jsonld::LD; use crate::routes::activitypub::jsonld::LD;
@ -20,13 +20,15 @@ pub struct Model {
} }
impl ActiveModel { impl ActiveModel {
pub fn new(document: &impl apb::Document, object: String) -> Result<ActiveModel, super::FieldError> { // TODO receive an impl, not a specific type!
// issue is that it's either an apb::Link or apb::Document, but Document doesnt inherit from link!
pub fn new(document: &serde_json::Value, object: String) -> Result<ActiveModel, super::FieldError> {
Ok(ActiveModel { Ok(ActiveModel {
id: sea_orm::ActiveValue::NotSet, id: sea_orm::ActiveValue::NotSet,
object: Set(object), object: Set(object),
url: Set(document.url().id().ok_or(super::FieldError("url"))?), url: Set(document.url().id().unwrap_or_else(|| document.href().to_string())),
document_type: Set(document.document_type().ok_or(super::FieldError("type"))?), document_type: Set(document.document_type().unwrap_or(apb::DocumentType::Page)),
media_type: Set(document.media_type().ok_or(super::FieldError("mediaType"))?.to_string()), media_type: Set(document.media_type().unwrap_or("link").to_string()),
name: Set(document.name().map(|x| x.to_string())), name: Set(document.name().map(|x| x.to_string())),
created: Set(document.published().unwrap_or(chrono::Utc::now())), created: Set(document.published().unwrap_or(chrono::Utc::now())),
}) })