diff --git a/.github/workflows/tauri2_ci.yaml b/.github/workflows/tauri2_ci.yaml index 5bf8cbb09f..6bbb7928ee 100644 --- a/.github/workflows/tauri2_ci.yaml +++ b/.github/workflows/tauri2_ci.yaml @@ -20,34 +20,34 @@ concurrency: cancel-in-progress: true jobs: - tauri-build-self-hosted: - if: github.event.pull_request.head.repo.full_name == github.repository - runs-on: self-hosted - - steps: - - uses: actions/checkout@v4 - - name: install frontend dependencies - working-directory: frontend/appflowy_web_app - run: | - mkdir dist - pnpm install - cd src-tauri && cargo build - - - name: test and lint - working-directory: frontend/appflowy_web_app - run: | - pnpm run lint:tauri - - - uses: tauri-apps/tauri-action@v0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tauriScript: pnpm tauri - projectPath: frontend/appflowy_web_app - args: "--debug" + # tauri-build-self-hosted: + # if: github.event.pull_request.head.repo.full_name == github.repository + # runs-on: self-hosted + # + # steps: + # - uses: actions/checkout@v4 + # - name: install frontend dependencies + # working-directory: frontend/appflowy_web_app + # run: | + # mkdir dist + # pnpm install + # cd src-tauri && cargo build + # + # - name: test and lint + # working-directory: frontend/appflowy_web_app + # run: | + # pnpm run lint:tauri + # + # - uses: tauri-apps/tauri-action@v0 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # tauriScript: pnpm tauri + # projectPath: frontend/appflowy_web_app + # args: "--debug" tauri-build-ubuntu: - if: github.event.pull_request.head.repo.full_name != github.repository + #if: github.event.pull_request.head.repo.full_name != github.repository runs-on: ubuntu-20.04 steps: diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/model_request.rs b/frontend/rust-lib/flowy-ai/src/local_ai/model_request.rs index 5d972de54f..c37a6f04ff 100644 --- a/frontend/rust-lib/flowy-ai/src/local_ai/model_request.rs +++ b/frontend/rust-lib/flowy-ai/src/local_ai/model_request.rs @@ -122,7 +122,7 @@ mod test { #[tokio::test] async fn retrieve_gpt4all_model_test() { for url in [ - "https://gpt4all.io/models/gguf/all-MiniLM-L6-v2-f16.gguf", + // "https://gpt4all.io/models/gguf/all-MiniLM-L6-v2-f16.gguf", "https://huggingface.co/second-state/All-MiniLM-L6-v2-Embedding-GGUF/resolve/main/all-MiniLM-L6-v2-Q3_K_L.gguf?download=true", // "https://huggingface.co/MaziyarPanahi/Mistral-7B-Instruct-v0.3-GGUF/resolve/main/Mistral-7B-Instruct-v0.3.Q4_K_M.gguf?download=true", ] { @@ -134,7 +134,7 @@ mod test { let cancel_token = CancellationToken::new(); let token = cancel_token.clone(); tokio::spawn(async move { - tokio::time::sleep(tokio::time::Duration::from_secs(30)).await; + tokio::time::sleep(tokio::time::Duration::from_secs(120)).await; token.cancel(); }); diff --git a/frontend/rust-lib/flowy-core/src/integrate/collab_interact.rs b/frontend/rust-lib/flowy-core/src/integrate/collab_interact.rs index 171fc20010..721c117cf3 100644 --- a/frontend/rust-lib/flowy-core/src/integrate/collab_interact.rs +++ b/frontend/rust-lib/flowy-core/src/integrate/collab_interact.rs @@ -7,7 +7,7 @@ use flowy_document::manager::DocumentManager; use flowy_document::reminder::{DocumentReminder, DocumentReminderAction}; use flowy_folder_pub::cloud::Error; use flowy_user::services::collab_interact::CollabInteract; -use lib_infra::future::FutureResult; +use lib_infra::async_trait::async_trait; pub struct CollabInteractImpl { #[allow(dead_code)] @@ -16,50 +16,42 @@ pub struct CollabInteractImpl { pub(crate) document_manager: Weak, } +#[async_trait] impl CollabInteract for CollabInteractImpl { - fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> { - let cloned_document_manager = self.document_manager.clone(); - FutureResult::new(async move { - if let Some(document_manager) = cloned_document_manager.upgrade() { - match DocumentReminder::try_from(reminder) { - Ok(reminder) => { - document_manager - .handle_reminder_action(DocumentReminderAction::Add { reminder }) - .await; - }, - Err(e) => tracing::error!("Failed to add reminder: {:?}", e), - } + async fn add_reminder(&self, reminder: Reminder) -> Result<(), Error> { + if let Some(document_manager) = self.document_manager.upgrade() { + match DocumentReminder::try_from(reminder) { + Ok(reminder) => { + document_manager + .handle_reminder_action(DocumentReminderAction::Add { reminder }) + .await; + }, + Err(e) => tracing::error!("Failed to add reminder: {:?}", e), } - Ok(()) - }) + } + Ok(()) } - fn remove_reminder(&self, reminder_id: &str) -> FutureResult<(), Error> { + async fn remove_reminder(&self, reminder_id: &str) -> Result<(), Error> { let reminder_id = reminder_id.to_string(); - let cloned_document_manager = self.document_manager.clone(); - FutureResult::new(async move { - if let Some(document_manager) = cloned_document_manager.upgrade() { - let action = DocumentReminderAction::Remove { reminder_id }; - document_manager.handle_reminder_action(action).await; - } - Ok(()) - }) + if let Some(document_manager) = self.document_manager.upgrade() { + let action = DocumentReminderAction::Remove { reminder_id }; + document_manager.handle_reminder_action(action).await; + } + Ok(()) } - fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error> { - let cloned_document_manager = self.document_manager.clone(); - FutureResult::new(async move { - if let Some(document_manager) = cloned_document_manager.upgrade() { - match DocumentReminder::try_from(reminder) { - Ok(reminder) => { - document_manager - .handle_reminder_action(DocumentReminderAction::Update { reminder }) - .await; - }, - Err(e) => tracing::error!("Failed to update reminder: {:?}", e), - } + async fn update_reminder(&self, reminder: Reminder) -> Result<(), Error> { + if let Some(document_manager) = self.document_manager.upgrade() { + match DocumentReminder::try_from(reminder) { + Ok(reminder) => { + document_manager + .handle_reminder_action(DocumentReminderAction::Update { reminder }) + .await; + }, + Err(e) => tracing::error!("Failed to update reminder: {:?}", e), } - Ok(()) - }) + } + Ok(()) } } diff --git a/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs b/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs index 01ef68636f..cabc5cd97f 100644 --- a/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs +++ b/frontend/rust-lib/flowy-core/src/integrate/trait_impls.rs @@ -48,40 +48,39 @@ use crate::integrate::server::{Server, ServerProvider}; #[async_trait] impl StorageCloudService for ServerProvider { - fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult { - let server = self.get_server(); - FutureResult::new(async move { - let storage = server?.file_storage().ok_or(FlowyError::internal())?; - storage.get_object_url(object_id).await - }) + async fn get_object_url(&self, object_id: ObjectIdentity) -> Result { + let storage = self + .get_server()? + .file_storage() + .ok_or(FlowyError::internal())?; + storage.get_object_url(object_id).await } - fn put_object(&self, url: String, val: ObjectValue) -> FutureResult<(), FlowyError> { - let server = self.get_server(); - FutureResult::new(async move { - let storage = server?.file_storage().ok_or(FlowyError::internal())?; - storage.put_object(url, val).await - }) + async fn put_object(&self, url: String, val: ObjectValue) -> Result<(), FlowyError> { + let storage = self + .get_server()? + .file_storage() + .ok_or(FlowyError::internal())?; + storage.put_object(url, val).await } - fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError> { - let server = self.get_server(); - let url = url.to_string(); - FutureResult::new(async move { - let storage = server?.file_storage().ok_or(FlowyError::internal())?; - storage.delete_object(&url).await - }) + async fn delete_object(&self, url: &str) -> Result<(), FlowyError> { + let storage = self + .get_server()? + .file_storage() + .ok_or(FlowyError::internal())?; + storage.delete_object(url).await } - fn get_object(&self, url: String) -> FutureResult { - let server = self.get_server(); - FutureResult::new(async move { - let storage = server?.file_storage().ok_or(FlowyError::internal())?; - storage.get_object(url).await - }) + async fn get_object(&self, url: String) -> Result { + let storage = self + .get_server()? + .file_storage() + .ok_or(FlowyError::internal())?; + storage.get_object(url).await } - fn get_object_url_v1( + async fn get_object_url_v1( &self, workspace_id: &str, parent_dir: &str, @@ -89,7 +88,9 @@ impl StorageCloudService for ServerProvider { ) -> FlowyResult { let server = self.get_server()?; let storage = server.file_storage().ok_or(FlowyError::internal())?; - storage.get_object_url_v1(workspace_id, parent_dir, file_id) + storage + .get_object_url_v1(workspace_id, parent_dir, file_id) + .await } async fn create_upload( diff --git a/frontend/rust-lib/flowy-folder-pub/src/cloud.rs b/frontend/rust-lib/flowy-folder-pub/src/cloud.rs index c34de4a3af..4747a4eb51 100644 --- a/frontend/rust-lib/flowy-folder-pub/src/cloud.rs +++ b/frontend/rust-lib/flowy-folder-pub/src/cloud.rs @@ -1,12 +1,13 @@ +use crate::entities::{PublishInfoResponse, PublishPayload}; pub use anyhow::Error; use collab_entity::CollabType; pub use collab_folder::{Folder, FolderData, Workspace}; +use lib_infra::async_trait::async_trait; +use lib_infra::future::FutureResult; use uuid::Uuid; -use crate::entities::{PublishInfoResponse, PublishPayload}; -use lib_infra::future::FutureResult; - /// [FolderCloudService] represents the cloud service for folder. +#[async_trait] pub trait FolderCloudService: Send + Sync + 'static { /// Creates a new workspace for the user. /// Returns error if the cloud service doesn't support multiple workspaces diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/file_storage.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/file_storage.rs index 868559bcbb..d1ecd22449 100644 --- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/file_storage.rs +++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/file_storage.rs @@ -1,11 +1,9 @@ +use crate::af_cloud::AFServer; use client_api::entity::{CompleteUploadRequest, CreateUploadRequest}; -use flowy_error::{FlowyError, FlowyResult}; +use flowy_error::FlowyError; use flowy_storage_pub::cloud::{ObjectIdentity, ObjectValue, StorageCloudService}; use flowy_storage_pub::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartResponse}; use lib_infra::async_trait::async_trait; -use lib_infra::future::FutureResult; - -use crate::af_cloud::AFServer; pub struct AFCloudFileStorageServiceImpl(pub T); @@ -20,56 +18,44 @@ impl StorageCloudService for AFCloudFileStorageServiceImpl where T: AFServer, { - fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult { - let try_get_client = self.0.try_get_client(); - FutureResult::new(async move { - let file_name = format!("{}.{}", object_id.file_id, object_id.ext); - let client = try_get_client?; - let url = client.get_blob_url(&object_id.workspace_id, &file_name); - Ok(url) + async fn get_object_url(&self, object_id: ObjectIdentity) -> Result { + let file_name = format!("{}.{}", object_id.file_id, object_id.ext); + let url = self + .0 + .try_get_client()? + .get_blob_url(&object_id.workspace_id, &file_name); + Ok(url) + } + + async fn put_object(&self, url: String, file: ObjectValue) -> Result<(), FlowyError> { + let client = self.0.try_get_client()?; + client.put_blob(&url, file.raw, &file.mime).await?; + Ok(()) + } + + async fn delete_object(&self, url: &str) -> Result<(), FlowyError> { + self.0.try_get_client()?.delete_blob(url).await?; + Ok(()) + } + + async fn get_object(&self, url: String) -> Result { + let (mime, raw) = self.0.try_get_client()?.get_blob(&url).await?; + Ok(ObjectValue { + raw: raw.into(), + mime, }) } - fn put_object(&self, url: String, file: ObjectValue) -> FutureResult<(), FlowyError> { - let try_get_client = self.0.try_get_client(); - let file = file.clone(); - FutureResult::new(async move { - let client = try_get_client?; - client.put_blob(&url, file.raw, &file.mime).await?; - Ok(()) - }) - } - - fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError> { - let url = url.to_string(); - let try_get_client = self.0.try_get_client(); - FutureResult::new(async move { - let client = try_get_client?; - client.delete_blob(&url).await?; - Ok(()) - }) - } - - fn get_object(&self, url: String) -> FutureResult { - let try_get_client = self.0.try_get_client(); - FutureResult::new(async move { - let client = try_get_client?; - let (mime, raw) = client.get_blob(&url).await?; - Ok(ObjectValue { - raw: raw.into(), - mime, - }) - }) - } - - fn get_object_url_v1( + async fn get_object_url_v1( &self, workspace_id: &str, parent_dir: &str, file_id: &str, - ) -> FlowyResult { - let client = self.0.try_get_client()?; - let url = client.get_blob_url_v1(workspace_id, parent_dir, file_id); + ) -> Result { + let url = self + .0 + .try_get_client()? + .get_blob_url_v1(workspace_id, parent_dir, file_id); Ok(url) } diff --git a/frontend/rust-lib/flowy-server/src/supabase/file_storage/mod.rs b/frontend/rust-lib/flowy-server/src/supabase/file_storage/mod.rs index ebfc707dcb..5da091c22c 100644 --- a/frontend/rust-lib/flowy-server/src/supabase/file_storage/mod.rs +++ b/frontend/rust-lib/flowy-server/src/supabase/file_storage/mod.rs @@ -1,7 +1,5 @@ pub use entities::*; -pub use plan::*; mod builder; pub mod core; mod entities; -pub mod plan; diff --git a/frontend/rust-lib/flowy-server/src/supabase/file_storage/plan.rs b/frontend/rust-lib/flowy-server/src/supabase/file_storage/plan.rs deleted file mode 100644 index 01482b1099..0000000000 --- a/frontend/rust-lib/flowy-server/src/supabase/file_storage/plan.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::sync::Weak; - -use parking_lot::RwLock; - -use flowy_error::FlowyError; -use flowy_storage_pub::cloud::{FileStoragePlan, StorageObject}; -use lib_infra::future::FutureResult; - -use crate::supabase::api::RESTfulPostgresServer; - -#[derive(Default)] -pub struct FileStoragePlanImpl { - #[allow(dead_code)] - uid: Weak>>, - #[allow(dead_code)] - postgrest: Option>, -} - -impl FileStoragePlanImpl { - pub fn new( - uid: Weak>>, - postgrest: Option>, - ) -> Self { - Self { uid, postgrest } - } -} - -impl FileStoragePlan for FileStoragePlanImpl { - fn storage_size(&self) -> FutureResult { - // 1 GB - FutureResult::new(async { Ok(1024 * 1024 * 1024) }) - } - - fn maximum_file_size(&self) -> FutureResult { - // 5 MB - FutureResult::new(async { Ok(5 * 1024 * 1024) }) - } - - fn check_upload_object(&self, _object: &StorageObject) -> FutureResult<(), FlowyError> { - FutureResult::new(async { Ok(()) }) - } -} diff --git a/frontend/rust-lib/flowy-storage-pub/src/cloud.rs b/frontend/rust-lib/flowy-storage-pub/src/cloud.rs index 816de17beb..7fb40c09fb 100644 --- a/frontend/rust-lib/flowy-storage-pub/src/cloud.rs +++ b/frontend/rust-lib/flowy-storage-pub/src/cloud.rs @@ -2,7 +2,6 @@ use crate::storage::{CompletedPartRequest, CreateUploadResponse, UploadPartRespo use async_trait::async_trait; use bytes::Bytes; use flowy_error::{FlowyError, FlowyResult}; -use lib_infra::future::FutureResult; use mime::Mime; #[async_trait] @@ -15,7 +14,7 @@ pub trait StorageCloudService: Send + Sync { /// # Returns /// - `Ok()` /// - `Err(Error)`: An error occurred during the operation. - fn get_object_url(&self, object_id: ObjectIdentity) -> FutureResult; + async fn get_object_url(&self, object_id: ObjectIdentity) -> Result; /// Creates a new storage object. /// @@ -25,7 +24,7 @@ pub trait StorageCloudService: Send + Sync { /// # Returns /// - `Ok()` /// - `Err(Error)`: An error occurred during the operation. - fn put_object(&self, url: String, object_value: ObjectValue) -> FutureResult<(), FlowyError>; + async fn put_object(&self, url: String, object_value: ObjectValue) -> Result<(), FlowyError>; /// Deletes a storage object by its URL. /// @@ -35,7 +34,7 @@ pub trait StorageCloudService: Send + Sync { /// # Returns /// - `Ok()` /// - `Err(Error)`: An error occurred during the operation. - fn delete_object(&self, url: &str) -> FutureResult<(), FlowyError>; + async fn delete_object(&self, url: &str) -> Result<(), FlowyError>; /// Fetches a storage object by its URL. /// @@ -45,8 +44,8 @@ pub trait StorageCloudService: Send + Sync { /// # Returns /// - `Ok(File)`: The returned file object. /// - `Err(Error)`: An error occurred during the operation. - fn get_object(&self, url: String) -> FutureResult; - fn get_object_url_v1( + async fn get_object(&self, url: String) -> Result; + async fn get_object_url_v1( &self, workspace_id: &str, parent_dir: &str, @@ -81,13 +80,6 @@ pub trait StorageCloudService: Send + Sync { ) -> Result<(), FlowyError>; } -pub trait FileStoragePlan: Send + Sync + 'static { - fn storage_size(&self) -> FutureResult; - fn maximum_file_size(&self) -> FutureResult; - - fn check_upload_object(&self, object: &StorageObject) -> FutureResult<(), FlowyError>; -} - pub struct ObjectIdentity { pub workspace_id: String, pub file_id: String, diff --git a/frontend/rust-lib/flowy-storage/src/manager.rs b/frontend/rust-lib/flowy-storage/src/manager.rs index fb96e18529..69455666e8 100644 --- a/frontend/rust-lib/flowy-storage/src/manager.rs +++ b/frontend/rust-lib/flowy-storage/src/manager.rs @@ -263,11 +263,10 @@ impl StorageService for StorageServiceImpl { let conn = self .user_service .sqlite_connection(self.user_service.user_id()?)?; - let url = self.cloud_service.get_object_url_v1( - &record.workspace_id, - &record.parent_dir, - &record.file_id, - )?; + let url = self + .cloud_service + .get_object_url_v1(&record.workspace_id, &record.parent_dir, &record.file_id) + .await?; let file_id = record.file_id.clone(); match insert_upload_file(conn, &record) { Ok(_) => { diff --git a/frontend/rust-lib/flowy-user/src/services/collab_interact.rs b/frontend/rust-lib/flowy-user/src/services/collab_interact.rs index d01d3cffde..1a54dd5f7e 100644 --- a/frontend/rust-lib/flowy-user/src/services/collab_interact.rs +++ b/frontend/rust-lib/flowy-user/src/services/collab_interact.rs @@ -1,25 +1,21 @@ use anyhow::Error; use collab_entity::reminder::Reminder; +use lib_infra::async_trait::async_trait; -use lib_infra::future::FutureResult; - +#[async_trait] pub trait CollabInteract: Send + Sync + 'static { - fn add_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>; - fn remove_reminder(&self, reminder_id: &str) -> FutureResult<(), Error>; - fn update_reminder(&self, reminder: Reminder) -> FutureResult<(), Error>; + async fn add_reminder(&self, _reminder: Reminder) -> Result<(), Error> { + Ok(()) + } + async fn remove_reminder(&self, _reminder_id: &str) -> Result<(), Error> { + Ok(()) + } + async fn update_reminder(&self, _reminder: Reminder) -> Result<(), Error> { + Ok(()) + } } pub struct DefaultCollabInteract; -impl CollabInteract for DefaultCollabInteract { - fn add_reminder(&self, _reminder: Reminder) -> FutureResult<(), Error> { - FutureResult::new(async { Ok(()) }) - } - fn remove_reminder(&self, _reminder_id: &str) -> FutureResult<(), Error> { - FutureResult::new(async { Ok(()) }) - } - - fn update_reminder(&self, _reminder: Reminder) -> FutureResult<(), Error> { - FutureResult::new(async { Ok(()) }) - } -} +#[async_trait] +impl CollabInteract for DefaultCollabInteract {}