From c6a2c049217c06ccc50b3cd67136152c3a8a1111 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 30 Aug 2026 12:44:52 +0200 Subject: [PATCH] add thumbnail data to attachment model --- application/backend/src/backend.rs | 5 ++++- entity/src/attachment.rs | 2 ++ migration/src/m20260502_184134_create_settings.rs | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index aa03c9d..f3646e8 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -917,6 +917,9 @@ impl BackendHandle { .into_tuple::() .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), diff --git a/entity/src/attachment.rs b/entity/src/attachment.rs index b6144a3..5fb4833 100644 --- a/entity/src/attachment.rs +++ b/entity/src/attachment.rs @@ -41,6 +41,8 @@ pub struct Model { pub title: String, pub content_type: String, + pub thumbnail: Option>, + pub lastmodified: DateTimeWithTimeZone, pub created: DateTimeWithTimeZone, } diff --git a/migration/src/m20260502_184134_create_settings.rs b/migration/src/m20260502_184134_create_settings.rs index 07ce8e4..c258f41 100644 --- a/migration/src/m20260502_184134_create_settings.rs +++ b/migration/src/m20260502_184134_create_settings.rs @@ -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() -- 2.52.0