use std::future::Future;
use std::pin::Pin;
-use sea_orm::{ActiveModelTrait, Database, DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait, Set, QueryOrder, DbErr, ExprTrait};
+use sea_orm::{ActiveModelTrait, Database, DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait, Set, QueryOrder, DbErr, ExprTrait, RelationTrait, QuerySelect};
use tokio::runtime::Runtime;
use std::sync::{Arc};
use std::thread::JoinHandle;
use tokio::sync::{broadcast, mpsc};
use tokio::sync::broadcast::error::SendError;
-use migration::{Expr, Migrator, MigratorTrait};
+use migration::{Expr, JoinType, Migrator, MigratorTrait};
use ui_rs::ui;
use entity::{collection, note, notecontent, profile, repository};
use entity::profile::Entity as Profile;
-use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, Node};
+use entity::collection::{create_notebook_hierarchy, CollectionType, Entity as Collection, LocalStorageSetting, Node};
use entity::note::{Column, Entity as Note};
use entity::notecontent::{Entity as NoteContent};
use migration::prelude::Utc;
where F: FnOnce(SaveNoteResult) + Send + 'static {
let bhandle = self.clone();
let cmd = Box::pin(async move {
+ let local_storage_path = if let Set(collection_id) = note.collection_id {
+ let result = collection::Entity::find_by_id(collection_id)
+ .join(JoinType::InnerJoin, collection::Relation::Repository.def())
+ .select_only()
+ .column(collection::Column::Storage)
+ .column(repository::Column::UseLocalStorage)
+ .column(repository::Column::LocalPath)
+ .into_tuple::<(LocalStorageSetting, bool, Option<String>)>()
+ .one(&bhandle.backend.db).await;
+ let col = result.ok().flatten().unwrap();
+
+ if col.0 == LocalStorageSetting::FileSystem || (col.0 == LocalStorageSetting::Default && col.1) {
+ if col.2.is_none() {
+ println!("Warning: collection is configured to use local storage, but there is no local storage path configured in the repository");
+ }
+ col.2
+ } else {
+ None
+ }
+ } else {
+ return;
+ };
+
let result = if let Set(note_id) = note.note_id {
let mut update = Note::update_many();
if let Set(kind) = note.kind {
use std::collections::HashMap;
use sea_orm::entity::prelude::*;
+#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "collection")]
pub struct Model {
pub profile_id: i32,
pub repository_id: i32,
+ #[sea_orm(belongs_to, from = "repository_id", to = "repository_id")]
+ pub repository: HasOne<super::repository::Entity>,
+
pub name: String,
pub parent: String,
pub icon: String,
Database = 2
}
-#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
-pub enum Relation {}
+//#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
+//pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}