Compare commits
No commits in common. "aa19211b8e9decc5d4c9dfec9ae1549aa34074a0" and "d74af76b60704d96d99c5f2f913dd70f5c04b853" have entirely different histories.
aa19211b8e
...
d74af76b60
5 changed files with 7 additions and 31 deletions
|
@ -22,14 +22,13 @@ pub struct Model {
|
|||
impl ActiveModel {
|
||||
// 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, media_type: Option<String>) -> Result<ActiveModel, super::FieldError> {
|
||||
let media_type = media_type.unwrap_or_else(|| document.media_type().unwrap_or("link").to_string());
|
||||
pub fn new(document: &serde_json::Value, object: String) -> Result<ActiveModel, super::FieldError> {
|
||||
Ok(ActiveModel {
|
||||
id: sea_orm::ActiveValue::NotSet,
|
||||
object: Set(object),
|
||||
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(media_type),
|
||||
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())),
|
||||
})
|
||||
|
|
|
@ -292,25 +292,14 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
|
|||
}
|
||||
|
||||
for attachment in object.attachment() {
|
||||
let attachment_model = model::attachment::ActiveModel::new(&attachment, object_model.id.clone(), None)?;
|
||||
let attachment_model = model::attachment::ActiveModel::new(&attachment, object_model.id.clone())?;
|
||||
model::attachment::Entity::insert(attachment_model)
|
||||
.exec(ctx.db())
|
||||
.await?;
|
||||
}
|
||||
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
||||
if let Some(img) = object.image().get() {
|
||||
// TODO lemmy doesnt tell us the media type but we use it to display the thing...
|
||||
let img_url = img.url().id().unwrap_or_default();
|
||||
let media_type = if img_url.ends_with("png") {
|
||||
Some("image/png".to_string())
|
||||
} else if img_url.ends_with("webp") {
|
||||
Some("image/webp".to_string())
|
||||
} else if img_url.ends_with("jpeg") || img_url.ends_with("jpg") {
|
||||
Some("image/jpeg".to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let attachment_model = model::attachment::ActiveModel::new(img, object_model.id.clone(), media_type)?;
|
||||
let attachment_model = model::attachment::ActiveModel::new(img, object_model.id.clone())?;
|
||||
model::attachment::Entity::insert(attachment_model)
|
||||
.exec(ctx.db())
|
||||
.await?;
|
||||
|
|
|
@ -54,25 +54,14 @@ impl apb::server::Inbox for Context {
|
|||
model::object::Entity::insert(object_model.into_active_model()).exec(self.db()).await?;
|
||||
model::activity::Entity::insert(activity_model.into_active_model()).exec(self.db()).await?;
|
||||
for attachment in object_node.attachment() {
|
||||
let attachment_model = model::attachment::ActiveModel::new(&attachment, oid.clone(), None)?;
|
||||
let attachment_model = model::attachment::ActiveModel::new(&attachment, oid.clone())?;
|
||||
model::attachment::Entity::insert(attachment_model)
|
||||
.exec(self.db())
|
||||
.await?;
|
||||
}
|
||||
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
||||
if let Some(img) = object_node.image().get() {
|
||||
// TODO lemmy doesnt tell us the media type but we use it to display the thing...
|
||||
let img_url = img.url().id().unwrap_or_default();
|
||||
let media_type = if img_url.ends_with("png") {
|
||||
Some("image/png".to_string())
|
||||
} else if img_url.ends_with("webp") {
|
||||
Some("image/webp".to_string())
|
||||
} else if img_url.ends_with("jpeg") || img_url.ends_with("jpg") {
|
||||
Some("image/jpeg".to_string())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let attachment_model = model::attachment::ActiveModel::new(img, oid.clone(), media_type)?;
|
||||
let attachment_model = model::attachment::ActiveModel::new(img, oid.clone())?;
|
||||
model::attachment::Entity::insert(attachment_model)
|
||||
.exec(self.db())
|
||||
.await?;
|
||||
|
|
|
@ -186,7 +186,6 @@
|
|||
border: 3px solid #bf616a;
|
||||
padding: 5px;
|
||||
object-fit: cover;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
img.expand,
|
||||
video.expand {
|
||||
|
|
|
@ -28,7 +28,7 @@ pub fn Attachment(
|
|||
view! {
|
||||
<p class="center">
|
||||
<img
|
||||
class="attachment"
|
||||
class="attachment ml-1"
|
||||
class:expand=expand
|
||||
src={move || if sensitive && !expand.get() {
|
||||
URL_SENSITIVE.to_string()
|
||||
|
|
Loading…
Reference in a new issue