]> uap-core.de Git - note.git/commitdiff
implement storing the content of a a new file note in the database in add_file_note main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 16 Aug 2026 11:49:27 +0000 (13:49 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 16 Aug 2026 11:49:27 +0000 (13:49 +0200)
application/backend/src/backend.rs

index 87feda5288b1f78c97f840dbbeae010291d6056e..d5e8d61917c27a958c4ad36e7561164fffbe3309 100644 (file)
@@ -42,7 +42,7 @@ use tokio::sync::{broadcast, mpsc};
 use tokio::sync::broadcast::error::SendError;
 use migration::{Expr, Migrator, MigratorTrait};
 
-use entity::{collection, note, notecontent, profile, repository};
+use entity::{collection, filecontent, note, notecontent, profile, repository};
 use entity::profile::Entity as Profile;
 use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node};
 use entity::note::{Column, Entity as Note, NoteType};
@@ -759,11 +759,7 @@ impl BackendHandle {
                 Ok(RenameNoteRet::Ok)
             }.await;
 
-            let res = match result {
-                Ok(r) => r,
-                Err(e) => RenameNoteRet::Error(e)
-            };
-
+            let res = result.unwrap_or_else(|e| RenameNoteRet::Error(e));
             callback(res);
         });
         let _ = self.tx.send(cmd);
@@ -849,7 +845,17 @@ impl BackendHandle {
                     }
                 } else {
                     // copy note content to the database
-                    // TODO
+                    let data = match fs::read(pathbuf.as_path()).await {
+                        Ok(data) => data,
+                        Err(e) => return Err(DbErr::Custom(e.to_string()))
+                    };
+
+                    let file_content = filecontent::ActiveModel {
+                        note_id: Set(model.note_id),
+                        content: Set(data),
+                        ..Default::default()
+                    };
+                    let _ = file_content.insert(&bhandle.backend.db).await?;
                 }
 
                 Ok(model)