From: Olaf Wintermann Date: Fri, 3 Jul 2026 18:52:39 +0000 (+0200) Subject: determine local storage path when saving a note X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;ds=sidebyside;p=note.git determine local storage path when saving a note --- diff --git a/application/src/backend.rs b/application/src/backend.rs index 66c88da..057682e 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -29,18 +29,18 @@ 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; @@ -395,6 +395,29 @@ impl BackendHandle { 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)>() + .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 { diff --git a/entity/src/collection.rs b/entity/src/collection.rs index 91a5fa2..858ebd2 100644 --- a/entity/src/collection.rs +++ b/entity/src/collection.rs @@ -1,6 +1,7 @@ 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 { @@ -9,6 +10,9 @@ pub struct Model { pub profile_id: i32, pub repository_id: i32, + #[sea_orm(belongs_to, from = "repository_id", to = "repository_id")] + pub repository: HasOne, + pub name: String, pub parent: String, pub icon: String, @@ -39,8 +43,8 @@ pub enum LocalStorageSetting { Database = 2 } -#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +//#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] +//pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} diff --git a/entity/src/repository.rs b/entity/src/repository.rs index 7fa18c6..17ed22b 100644 --- a/entity/src/repository.rs +++ b/entity/src/repository.rs @@ -11,6 +11,8 @@ pub struct Model { pub name: String, pub local_path: Option, pub base_url: Option, + + pub use_local_storage: bool, } impl ActiveModelBehavior for ActiveModel {} diff --git a/migration/src/m20260502_184134_create_settings.rs b/migration/src/m20260502_184134_create_settings.rs index fac991b..89b54b3 100644 --- a/migration/src/m20260502_184134_create_settings.rs +++ b/migration/src/m20260502_184134_create_settings.rs @@ -28,6 +28,7 @@ impl MigrationTrait for Migration { .col(string("name")) .col(string_null("local_path")) .col(string_null("base_url")) + .col(boolean("use_local_storage").default(false)) .to_owned(), ) .await?;