let _ = self.tx.send(cmd);
}
+ pub fn check_nodename<F>(&self, collection_id: i32, note_id: i32, nodename: &str, callback: F)
+ where F: FnOnce(Result<bool, DbErr>) + 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<F>(&self, path: &Path, callback: F)
where F: FnOnce(std::io::Result<Metadata>) + Send + 'static {
let p = PathBuf::from(path);
Ok(path)
}
+
+pub async fn check_free_nodename(db: &DatabaseConnection, collection_id: i32, note_id: i32, nodename: &str) -> Result<bool, DbErr> {
+ 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::<i32>()
+ .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
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);
}
}