From 3ccb7bf1cdfc3e0f744f73dd4a9ee8fccbcbb678 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 1 Aug 2026 11:39:03 +0200 Subject: [PATCH] add backend function for checking if a nodename is available --- application/backend/src/backend.rs | 11 +++++++++++ application/backend/src/storage.rs | 23 +++++++++++++++++++++++ application/note/src/file.rs | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/application/backend/src/backend.rs b/application/backend/src/backend.rs index 2e46450..f1344ea 100644 --- a/application/backend/src/backend.rs +++ b/application/backend/src/backend.rs @@ -717,6 +717,17 @@ impl BackendHandle { let _ = self.tx.send(cmd); } + pub fn check_nodename(&self, collection_id: i32, note_id: i32, nodename: &str, callback: F) + where F: FnOnce(Result) + Send + 'static { + let bhandle = self.clone(); + let name = nodename.to_string(); + let cmd = Box::pin(async move { + let result = check_free_nodename(&bhandle.backend.db, collection_id, note_id, name.as_str()).await; + callback(result); + }); + let _ = self.tx.send(cmd); + } + pub fn get_file_metadata(&self, path: &Path, callback: F) where F: FnOnce(std::io::Result) + Send + 'static { let p = PathBuf::from(path); diff --git a/application/backend/src/storage.rs b/application/backend/src/storage.rs index a91ab75..7ce260a 100644 --- a/application/backend/src/storage.rs +++ b/application/backend/src/storage.rs @@ -136,3 +136,26 @@ pub async fn write_tmp_file(name: &str, data: Vec) -> std::io::Result Result { + let exists = note::Entity::find() + .filter(note::Column::CollectionId.eq(collection_id)) + .filter(note::Column::Nodename.eq(nodename)) + .select_only() + .column(note::Column::NoteId) + .into_tuple::() + .one(db).await?; + if exists.is_some() { + return Ok(false) + } + + let path = get_note_storage_path(db, note_id).await?; + if let Some(path) = path { + let m = fs::metadata(Path::new(&path)).await; + if m.is_ok() { + return Ok(false) // file exists + } + } + + Ok(true) +} \ No newline at end of file diff --git a/application/note/src/file.rs b/application/note/src/file.rs index bf357bb..559efce 100644 --- a/application/note/src/file.rs +++ b/application/note/src/file.rs @@ -133,7 +133,7 @@ impl FileNote { let url = Url::from_file_path(&path); if let Ok(url) = url { note.webview.load_url(url.as_str()); - // TODO: replace 1 with enum value + // TODO: replace 2 with enum value note.preview_tab.set(2); } } -- 2.52.0