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 {
|
impl ActiveModel {
|
||||||
// TODO receive an impl, not a specific type!
|
// 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!
|
// 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> {
|
pub fn new(document: &serde_json::Value, object: String) -> Result<ActiveModel, super::FieldError> {
|
||||||
let media_type = media_type.unwrap_or_else(|| document.media_type().unwrap_or("link").to_string());
|
|
||||||
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().unwrap_or_else(|| document.href().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)),
|
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())),
|
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())),
|
||||||
})
|
})
|
||||||
|
|
|
@ -292,25 +292,14 @@ async fn fetch_object_inner(ctx: &Context, id: &str, depth: usize) -> crate::Res
|
||||||
}
|
}
|
||||||
|
|
||||||
for attachment in object.attachment() {
|
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)
|
model::attachment::Entity::insert(attachment_model)
|
||||||
.exec(ctx.db())
|
.exec(ctx.db())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
||||||
if let Some(img) = object.image().get() {
|
if let Some(img) = object.image().get() {
|
||||||
// TODO lemmy doesnt tell us the media type but we use it to display the thing...
|
let attachment_model = model::attachment::ActiveModel::new(img, object_model.id.clone())?;
|
||||||
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)?;
|
|
||||||
model::attachment::Entity::insert(attachment_model)
|
model::attachment::Entity::insert(attachment_model)
|
||||||
.exec(ctx.db())
|
.exec(ctx.db())
|
||||||
.await?;
|
.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::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?;
|
model::activity::Entity::insert(activity_model.into_active_model()).exec(self.db()).await?;
|
||||||
for attachment in object_node.attachment() {
|
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)
|
model::attachment::Entity::insert(attachment_model)
|
||||||
.exec(self.db())
|
.exec(self.db())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
// lemmy sends us an image field in posts, treat it like an attachment i'd say
|
||||||
if let Some(img) = object_node.image().get() {
|
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 attachment_model = model::attachment::ActiveModel::new(img, oid.clone())?;
|
||||||
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)?;
|
|
||||||
model::attachment::Entity::insert(attachment_model)
|
model::attachment::Entity::insert(attachment_model)
|
||||||
.exec(self.db())
|
.exec(self.db())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -186,7 +186,6 @@
|
||||||
border: 3px solid #bf616a;
|
border: 3px solid #bf616a;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
}
|
||||||
img.expand,
|
img.expand,
|
||||||
video.expand {
|
video.expand {
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn Attachment(
|
||||||
view! {
|
view! {
|
||||||
<p class="center">
|
<p class="center">
|
||||||
<img
|
<img
|
||||||
class="attachment"
|
class="attachment ml-1"
|
||||||
class:expand=expand
|
class:expand=expand
|
||||||
src={move || if sensitive && !expand.get() {
|
src={move || if sensitive && !expand.get() {
|
||||||
URL_SENSITIVE.to_string()
|
URL_SENSITIVE.to_string()
|
||||||
|
|
Loading…
Reference in a new issue