From 488cac9703bc120f249bc9c247660e7a93a028cf Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 8 May 2024 02:26:18 +0200 Subject: [PATCH] fix: accept link attachments kind of hacky way but should work --- src/model/attachment.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/model/attachment.rs b/src/model/attachment.rs index aeb6530b..e508d1ba 100644 --- a/src/model/attachment.rs +++ b/src/model/attachment.rs @@ -1,4 +1,4 @@ -use apb::{DocumentMut, ObjectMut}; +use apb::{Document, DocumentMut, Link, Object, ObjectMut}; use sea_orm::{entity::prelude::*, Set}; use crate::routes::activitypub::jsonld::LD; @@ -20,13 +20,15 @@ pub struct Model { } impl ActiveModel { - pub fn new(document: &impl apb::Document, object: String) -> Result { + // 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 { Ok(ActiveModel { id: sea_orm::ActiveValue::NotSet, object: Set(object), - url: Set(document.url().id().ok_or(super::FieldError("url"))?), - document_type: Set(document.document_type().ok_or(super::FieldError("type"))?), - media_type: Set(document.media_type().ok_or(super::FieldError("mediaType"))?.to_string()), + url: Set(document.url().id().unwrap_or_else(|| document.href().to_string())), + document_type: Set(document.document_type().unwrap_or(apb::DocumentType::Page)), + media_type: Set(document.media_type().unwrap_or("link").to_string()), name: Set(document.name().map(|x| x.to_string())), created: Set(document.published().unwrap_or(chrono::Utc::now())), })