mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-16 01:26:37 +08:00
feat: add some ipc provider method
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
pub mod blob;
|
||||
pub mod workspace;
|
||||
|
||||
use workspace::{__cmd__create_workspace, __cmd__update_y_document};
|
||||
use blob::__cmd__put_blob;
|
||||
use blob::__cmd__get_blob;
|
||||
|
||||
use crate::{commands::{workspace::{create_workspace, update_y_document}, blob::{put_blob, get_blob}}};
|
||||
use blob::*;
|
||||
use workspace::*;
|
||||
|
||||
pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
|
||||
tauri::generate_handler![update_y_document, create_workspace, put_blob, get_blob]
|
||||
tauri::generate_handler![
|
||||
update_y_document,
|
||||
create_workspace,
|
||||
update_workspace,
|
||||
put_blob,
|
||||
get_blob
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub async fn put_blob<'s>(
|
||||
if let Ok(path) = blob_storage
|
||||
.put_blob(
|
||||
// TODO: ask octobase to accept blob directly or wrap/await tauri command to create a real stream, so we don't need to construct stream manually
|
||||
Some(parameters.workspace_id.to_string()),
|
||||
Some(parameters.workspace_id),
|
||||
stream::iter::<Vec<Bytes>>(vec![Bytes::from(parameters.blob)]),
|
||||
)
|
||||
.await
|
||||
@@ -37,7 +37,7 @@ pub async fn get_blob<'s>(
|
||||
let GetBlob { workspace_id, id } = parameters;
|
||||
// TODO: check user permission? Or just assume there will only be one user
|
||||
let blob_storage = &state.0.lock().await.blob_storage;
|
||||
if let Ok(mut file_stream) = blob_storage.get_blob(Some(workspace_id.to_string()), id.clone()).await {
|
||||
if let Ok(mut file_stream) = blob_storage.get_blob(Some(workspace_id.clone()), id.clone()).await {
|
||||
// Read all of the chunks into a vector.
|
||||
let mut stream_contents = Vec::new();
|
||||
let mut error_message = "".to_string();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use ipc_types::{document::YDocumentUpdate, workspace::CreateWorkspace};
|
||||
use jwst::{DocStorage, Workspace};
|
||||
use ipc_types::{
|
||||
document::YDocumentUpdate,
|
||||
workspace::{CreateWorkspace, CreateWorkspaceResult, UpdateWorkspace},
|
||||
};
|
||||
use jwst::{DocStorage, Workspace as OctoBaseWorkspace};
|
||||
use lib0::any::Any;
|
||||
|
||||
use crate::state::AppState;
|
||||
@@ -8,30 +11,51 @@ use crate::state::AppState;
|
||||
pub async fn create_workspace<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: CreateWorkspace,
|
||||
) -> Result<bool, String> {
|
||||
let workspace = Workspace::new(parameters.id.to_string());
|
||||
workspace.with_trx(|mut workspace_transaction| {
|
||||
// TODO: why this Any here?
|
||||
workspace_transaction.set_metadata("name", Any::String(parameters.name.into_boxed_str()));
|
||||
workspace_transaction.set_metadata(
|
||||
"avatar",
|
||||
Any::String(parameters.avatar.clone().into_boxed_str()),
|
||||
);
|
||||
});
|
||||
if let Err(error_message) = &state
|
||||
) -> Result<CreateWorkspaceResult, String> {
|
||||
match &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.doc_storage
|
||||
.write_doc(parameters.id, workspace.doc())
|
||||
.metadata_db
|
||||
.create_normal_workspace(parameters.user_id)
|
||||
.await
|
||||
{
|
||||
Err(error_message.to_string())
|
||||
} else {
|
||||
Ok(true)
|
||||
Ok(new_workspace) => {
|
||||
let workspace_doc = OctoBaseWorkspace::new(new_workspace.id.to_string());
|
||||
|
||||
workspace_doc.with_trx(|mut workspace_doc_transaction| {
|
||||
workspace_doc_transaction
|
||||
.set_metadata("name", Any::String(parameters.name.clone().into_boxed_str()));
|
||||
});
|
||||
if let Err(error_message) = &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.doc_storage
|
||||
.write_doc(new_workspace.id, workspace_doc.doc())
|
||||
.await
|
||||
{
|
||||
Err(error_message.to_string())
|
||||
} else {
|
||||
Ok(CreateWorkspaceResult {
|
||||
id: new_workspace.id.to_string(),
|
||||
name: parameters.name,
|
||||
})
|
||||
}
|
||||
}
|
||||
Err(error_message) => Err(error_message.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn update_workspace<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: UpdateWorkspace,
|
||||
) -> Result<bool, String> {
|
||||
// No thing to update now. The avatar is update in YDoc using websocket or yrs.update
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn update_y_document(parameters: YDocumentUpdate) -> Result<bool, String> {
|
||||
Ok(true)
|
||||
|
||||
Reference in New Issue
Block a user