mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
feat: add some ipc provider method
This commit is contained in:
Generated
+51
@@ -23,6 +23,16 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "Inflector"
|
||||
version = "0.11.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
@@ -1714,6 +1724,18 @@ dependencies = [
|
||||
"yrs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jwst-logger"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"nu-ansi-term",
|
||||
"tracing",
|
||||
"tracing-log",
|
||||
"tracing-stackdriver",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jwst-storage"
|
||||
version = "0.1.0"
|
||||
@@ -1725,6 +1747,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"futures",
|
||||
"jwst",
|
||||
"jwst-logger",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
@@ -4157,6 +4180,31 @@ dependencies = [
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-serde"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-stackdriver"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eff9dd91761e07727176a3dd3a1d64bbb577ea656b7b82fa4be4021832674c49"
|
||||
dependencies = [
|
||||
"Inflector",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"time 0.3.17",
|
||||
"tracing-core",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-subscriber"
|
||||
version = "0.3.16"
|
||||
@@ -4167,12 +4215,15 @@ dependencies = [
|
||||
"nu-ansi-term",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sharded-slab",
|
||||
"smallvec",
|
||||
"thread_local",
|
||||
"tracing",
|
||||
"tracing-core",
|
||||
"tracing-log",
|
||||
"tracing-serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use ipc_types::{blob::IBlobParameters, document::YDocumentUpdate, workspace::CreateWorkspace};
|
||||
use ipc_types::{blob::IBlobParameters, document::YDocumentUpdate, workspace::IWorkspaceParameters};
|
||||
/**
|
||||
* convert serde to jsonschema: https://imfeld.dev/writing/generating_typescript_types_from_rust
|
||||
* with way to optimize
|
||||
@@ -28,6 +28,6 @@ fn main() {
|
||||
"packages/data-center/src/provider/tauri-ipc/ipc/types",
|
||||
);
|
||||
generate::<YDocumentUpdate>(Path::join(&data_center_ipc_type_folder, "document.json"));
|
||||
generate::<CreateWorkspace>(Path::join(&data_center_ipc_type_folder, "workspace.json"));
|
||||
generate::<IWorkspaceParameters>(Path::join(&data_center_ipc_type_folder, "workspace.json"));
|
||||
generate::<IBlobParameters>(Path::join(&data_center_ipc_type_folder, "blob.json"));
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -3,13 +3,13 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct PutBlob {
|
||||
pub workspace_id: u64,
|
||||
pub workspace_id: String,
|
||||
pub blob: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GetBlob {
|
||||
pub workspace_id: u64,
|
||||
pub workspace_id: String,
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,29 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct CreateWorkspace {
|
||||
pub id: i64,
|
||||
// TODO: make all id string, on Octobase side, and rewrite all related tests
|
||||
pub user_id: i32,
|
||||
/**
|
||||
* only set name, avatar is update in datacenter to yDoc directly
|
||||
*/
|
||||
pub name: String,
|
||||
pub avatar: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct CreateWorkspaceResult {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct UpdateWorkspace {
|
||||
pub id: i64,
|
||||
pub public: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum IWorkspaceParameters {
|
||||
CreateWorkspace(CreateWorkspace),
|
||||
UpdateWorkspace(UpdateWorkspace),
|
||||
CreateWorkspaceResult(CreateWorkspaceResult),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user