.into_tuple::<i32>()
.one(&backend.db).await?.ok_or(DbErr::Custom("note not found".to_string()))?;
+ let content = fs::read(pathbuf).await.map_err(|e| DbErr::Custom(e.to_string()))?;
+
+ // TODO: create scaled down version for thumbnail if it is an image
let now: DateTimeWithTimeZone = Utc::now().into();
let new_attachment = attachment::ActiveModel {
attachment_id: Default::default(),
nodename: Set(file_name.clone()),
title: Set(file_name.clone()),
content_type: Set(nodename_to_contenttype(file_name.as_str()).to_string()),
+ thumbnail: Set(Some(content.clone())),
lastmodified: Set(now.clone()),
created: Set(now),
};
let attachment = new_attachment.insert(&backend.db).await?;
- let content = fs::read(pathbuf).await.map_err(|e| DbErr::Custom(e.to_string()))?;
let new_attachment_content = attachmentcontent::ActiveModel {
id: Default::default(),
attachment_id: Set(attachment.attachment_id),
pub title: String,
pub content_type: String,
+ pub thumbnail: Option<Vec<u8>>,
+
pub lastmodified: DateTimeWithTimeZone,
pub created: DateTimeWithTimeZone,
}
.col(string("nodename"))
.col(string("title"))
.col(string("content_type"))
+ .col(blob_null("thumbnail"))
.col(timestamp_with_time_zone("lastmodified"))
.col(timestamp_with_time_zone("created"))
.to_owned()