]> uap-core.de Git - note.git/commitdiff
add thumbnail data to attachment model
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 30 Aug 2026 10:44:52 +0000 (12:44 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 30 Aug 2026 10:44:52 +0000 (12:44 +0200)
application/backend/src/backend.rs
entity/src/attachment.rs
migration/src/m20260502_184134_create_settings.rs

index aa03c9d44d09c943b1e5377c5714c2ab430fb12e..f3646e8ad6d2d29f5c6c29b6dc31cbec37deef5c 100644 (file)
@@ -917,6 +917,9 @@ impl BackendHandle {
                     .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(),
@@ -925,12 +928,12 @@ impl BackendHandle {
                     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),
index b6144a3a187886cdbad71542d8585f283a58fb5d..5fb4833742ff4bba0285816367e68c28fe2cf7b2 100644 (file)
@@ -41,6 +41,8 @@ pub struct Model {
     pub title: String,
     pub content_type: String,
 
+    pub thumbnail: Option<Vec<u8>>,
+
     pub lastmodified: DateTimeWithTimeZone,
     pub created: DateTimeWithTimeZone,
 }
index 07ce8e4d834e102a65ecb237e2a37f345158fe77..c258f418581c134d473d1230e0d0ff4a6e31ea52 100644 (file)
@@ -142,6 +142,7 @@ impl MigrationTrait for Migration {
                     .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()