chore: update template

This commit is contained in:
Nathan 2025-04-24 15:45:38 +08:00
parent 76b9cbd446
commit 9e5a6df52c
13 changed files with 149 additions and 49 deletions

View File

@ -389,7 +389,7 @@ class _CreateWorkspaceButton extends StatelessWidget {
workspaceBloc.add(
UserWorkspaceEvent.createWorkspace(
name,
AuthTypePB.Server,
AuthTypePB.Local,
),
);
},

View File

@ -144,34 +144,34 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/window_manager/macos
SPEC CHECKSUMS:
app_links: 9028728e32c83a0831d9db8cf91c526d16cc5468
appflowy_backend: 464aeb3e5c6966a41641a2111e5ead72ce2695f7
auto_updater_macos: 3a42f1a06be6981f1a18be37e6e7bf86aa732118
bitsdojo_window_macos: 7959fb0ca65a3ccda30095c181ecb856fae48ea9
connectivity_plus: e74b9f74717d2d99d45751750e266e55912baeb5
desktop_drop: e0b672a7d84c0a6cbc378595e82cdb15f2970a43
device_info_plus: 4fb280989f669696856f8b129e4a5e3cd6c48f76
file_selector_macos: 6280b52b459ae6c590af5d78fc35c7267a3c4b31
flowy_infra_ui: 8760ff42a789de40bf5007a5f176b454722a341e
app_links: 10e0a0ab602ffaf34d142cd4862f29d34b303b2a
appflowy_backend: 865496343de667fc8c600e04b9fd05234e130cf9
auto_updater_macos: 3e3462c418fe4e731917eacd8d28eef7af84086d
bitsdojo_window_macos: 44e3b8fe3dd463820e0321f6256c5b1c16bb6a00
connectivity_plus: 18d3c32514c886e046de60e9c13895109866c747
desktop_drop: 69eeff437544aa619c8db7f4481b3a65f7696898
device_info_plus: 1b14eed9bf95428983aed283a8d51cce3d8c4215
file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d
flowy_infra_ui: 03301a39ad118771adbf051a664265c61c507f38
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
HotKey: 400beb7caa29054ea8d864c96f5ba7e5b4852277
hotkey_manager: b443f35f4d772162937aa73fd8995e579f8ac4e2
irondash_engine_context: 893c7d96d20ce361d7e996f39d360c4c2f9869ba
local_notifier: ebf072651e35ae5e47280ad52e2707375cb2ae4e
package_info_plus: f0052d280d17aa382b932f399edf32507174e870
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
hotkey_manager: c32bf0bfe8f934b7bc17ab4ad5c4c142960b023c
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
local_notifier: e9506bc66fc70311e8bc7291fb70f743c081e4ff
package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
ReachabilitySwift: 32793e867593cfc1177f5d16491e3a197d2fccda
screen_retriever_macos: 452e51764a9e1cdb74b3c541238795849f21557f
screen_retriever_macos: 776e0fa5d42c6163d2bf772d22478df4b302b161
Sentry: 1fe34e9c2cbba1e347623610d26db121dcb569f1
sentry_flutter: e24b397f9a61fa5bbefd8279c3b2242ca86faa90
share_plus: 510bf0af1a42cd602274b4629920c9649c52f4cc
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sentry_flutter: a39c2a2d67d5e5b9cb0b94a4985c76dd5b3fc737
share_plus: 1fa619de8392a4398bfaf176d441853922614e89
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
Sparkle: 5f8960a7a119aa7d45dacc0d5837017170bc5675
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
super_native_extensions: c2795d6d9aedf4a79fae25cb6160b71b50549189
url_launcher_macos: 0fba8ddabfc33ce0a9afe7c5fef5aab3d8d2d673
webview_flutter_wkwebview: 44d4dee7d7056d5ad185d25b38404436d56c547c
window_manager: e8d0b1431ab6c454f2b5c9ae26004bbfa43469aa
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
super_native_extensions: 85efee3a7495b46b04befcfc86ed12069264ebf3
url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4
window_manager: 990c8e348c4da2a93b81da638245d40554ec9436
PODFILE CHECKSUM: 0532f3f001ca3110b8be345d6491fff690e95823

View File

@ -493,7 +493,7 @@ checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
[[package]]
name = "app-error"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"bincode",
@ -513,7 +513,7 @@ dependencies = [
[[package]]
name = "appflowy-ai-client"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"bytes",
@ -1159,7 +1159,7 @@ dependencies = [
[[package]]
name = "client-api"
version = "0.2.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"again",
"anyhow",
@ -1214,7 +1214,7 @@ dependencies = [
[[package]]
name = "client-api-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"collab-entity",
"collab-rt-entity",
@ -1227,7 +1227,7 @@ dependencies = [
[[package]]
name = "client-websocket"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"futures-channel",
"futures-util",
@ -1499,7 +1499,7 @@ dependencies = [
[[package]]
name = "collab-rt-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"bincode",
@ -1521,7 +1521,7 @@ dependencies = [
[[package]]
name = "collab-rt-protocol"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"async-trait",
@ -1969,7 +1969,7 @@ checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308"
[[package]]
name = "database-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"bincode",
"bytes",
@ -2937,7 +2937,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"arc-swap",
"assert-json-diff",
"bytes",
"chrono",
"client-api",
@ -2948,7 +2947,6 @@ dependencies = [
"collab-folder",
"collab-plugins",
"collab-user",
"dotenv",
"flowy-ai",
"flowy-ai-pub",
"flowy-database-pub",
@ -2974,14 +2972,15 @@ dependencies = [
"tokio-stream",
"tokio-util",
"tracing",
"tracing-subscriber",
"uuid",
"workspace-template",
]
[[package]]
name = "flowy-server-pub"
version = "0.1.0"
dependencies = [
"client-api",
"flowy-error",
"serde",
"serde_repr",
@ -3426,7 +3425,7 @@ dependencies = [
[[package]]
name = "gotrue"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"getrandom 0.2.10",
@ -3441,7 +3440,7 @@ dependencies = [
[[package]]
name = "gotrue-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"app-error",
"jsonwebtoken",
@ -4065,7 +4064,7 @@ dependencies = [
[[package]]
name = "infra"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"bytes",
@ -6643,7 +6642,7 @@ dependencies = [
[[package]]
name = "shared-entity"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=954c323#954c32332487f5e17a7fb5be0bc339db1cb00e17"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"app-error",
@ -8616,6 +8615,27 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "workspace-template"
version = "0.1.0"
source = "git+https://github.com/AppFlowy-IO/AppFlowy-Cloud?rev=5826bffefb2509dcfa8b2ea7bb4037ed9290b713#5826bffefb2509dcfa8b2ea7bb4037ed9290b713"
dependencies = [
"anyhow",
"async-trait",
"collab",
"collab-database",
"collab-document",
"collab-entity",
"collab-folder",
"getrandom 0.2.10",
"indexmap 2.1.0",
"nanoid",
"serde",
"serde_json",
"tokio",
"uuid",
]
[[package]]
name = "write16"
version = "1.0.0"

View File

@ -108,8 +108,9 @@ af-local-ai = { version = "0.1" }
# Run the script.add_workspace_members:
# scripts/tool/update_client_api_rev.sh new_rev_id
# ⚠️⚠️⚠️️
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "954c323" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "954c323" }
client-api = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5826bffefb2509dcfa8b2ea7bb4037ed9290b713" }
client-api-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5826bffefb2509dcfa8b2ea7bb4037ed9290b713" }
workspace-template = { git = "https://github.com/AppFlowy-IO/AppFlowy-Cloud", rev = "5826bffefb2509dcfa8b2ea7bb4037ed9290b713" }
[profile.dev]
opt-level = 0

View File

@ -344,8 +344,8 @@ async fn af_cloud_create_local_workspace_test() {
let views = test.get_all_views().await;
assert_eq!(
views.len(),
2,
"Local workspace should have 2 default views"
3,
"Local workspace should have 3 default views"
);
assert!(
views

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
flowy-error = { workspace = true }
flowy-error = { workspace = true }
serde.workspace = true
serde_repr.workspace = true
client-api = { workspace = true }

View File

@ -1,3 +1,4 @@
pub use client_api::entity::*;
use serde_repr::Deserialize_repr;
macro_rules! if_native {

View File

@ -46,6 +46,7 @@ semver = "1.0.23"
flowy-sqlite = { workspace = true }
flowy-ai = { workspace = true }
chrono.workspace = true
workspace-template.workspace = true
[dependencies.client-api]
workspace = true
@ -59,9 +60,6 @@ features = [
[dev-dependencies]
uuid.workspace = true
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
dotenv = "0.15.0"
assert-json-diff = "2.0.2"
serde_json.workspace = true
[features]

View File

@ -1,16 +1,22 @@
#![allow(unused_variables)]
use crate::af_cloud::define::LoggedUser;
use crate::local_server::template::create_workspace::{
create_workspace_for_user, CreateWorkspaceCollab,
};
use crate::local_server::uid::UserIDGenerator;
use anyhow::Context;
use client_api::entity::GotrueTokenResponse;
use collab::core::origin::CollabOrigin;
use collab::preclude::Collab;
use collab_entity::CollabObject;
use collab_plugins::local_storage::kv::doc::CollabKVAction;
use collab_plugins::local_storage::kv::KVTransactionDB;
use collab_plugins::CollabKVDB;
use collab_user::core::UserAwareness;
use flowy_ai_pub::cloud::billing_dto::WorkspaceUsageAndLimit;
use flowy_ai_pub::cloud::{AFWorkspaceSettings, AFWorkspaceSettingsChange};
use flowy_error::FlowyError;
use flowy_error::{FlowyError, FlowyResult};
use flowy_user_pub::cloud::{UserCloudService, UserCollabParams};
use flowy_user_pub::entities::*;
use flowy_user_pub::sql::{
@ -163,6 +169,16 @@ impl UserCloudService for LocalServerUserServiceImpl {
async fn create_workspace(&self, workspace_name: &str) -> Result<UserWorkspace, FlowyError> {
let workspace_id = Uuid::new_v4();
let uid = self.logged_user.user_id()?;
let collab_db = self
.logged_user
.get_collab_db(uid)?
.upgrade()
.ok_or_else(FlowyError::ref_drop)?;
let collab_params = create_workspace_for_user(uid, &workspace_id).await?;
insert_collabs(collab_db, uid, &workspace_id.to_string(), collab_params)?;
// insert collab
let mut conn = self.logged_user.get_sqlite_db(uid)?;
let user_workspace =
insert_local_workspace(uid, &workspace_id.to_string(), workspace_name, &mut conn)?;
@ -339,3 +355,24 @@ impl UserCloudService for LocalServerUserServiceImpl {
})
}
}
fn insert_collabs(
db: Arc<CollabKVDB>,
uid: i64,
workspace_id: &str,
params_list: Vec<CreateWorkspaceCollab>,
) -> FlowyResult<()> {
let write = db.write_txn();
for params in params_list {
write.flush_doc(
uid,
workspace_id,
&params.object_id.to_string(),
params.encoded_collab.state_vector.to_vec(),
params.encoded_collab.doc_state.to_vec(),
)?
}
write.commit_transaction()?;
Ok(())
}

View File

@ -2,5 +2,6 @@ pub use server::*;
pub mod impls;
mod server;
mod template;
pub(crate) mod uid;
mod util;

View File

@ -0,0 +1,40 @@
use collab::entity::EncodedCollab;
use tracing::warn;
use uuid::Uuid;
use workspace_template::document::vault_template::VaultTemplate;
use workspace_template::{TemplateObjectId, WorkspaceTemplateBuilder};
pub async fn create_workspace_for_user(
uid: i64,
workspace_id: &Uuid,
) -> anyhow::Result<Vec<CreateWorkspaceCollab>> {
let templates = WorkspaceTemplateBuilder::new(uid, workspace_id)
.with_templates(vec![VaultTemplate])
.build()
.await?;
let mut collab_params = Vec::with_capacity(templates.len());
for template in templates {
let template_id = template.template_id;
let (_, object_id) = match &template_id {
TemplateObjectId::Document(oid) => (oid.to_string(), oid.to_string()),
TemplateObjectId::Folder(oid) => (oid.to_string(), oid.to_string()),
_ => {
warn!("Unsupported template type: {:?}", template_id,);
continue;
},
};
let object_id = Uuid::parse_str(&object_id)?;
collab_params.push(CreateWorkspaceCollab {
object_id,
encoded_collab: template.encoded_collab,
});
}
Ok(collab_params)
}
pub struct CreateWorkspaceCollab {
pub object_id: Uuid,
pub encoded_collab: EncodedCollab,
}

View File

@ -0,0 +1 @@
pub mod create_workspace;

View File

@ -15,6 +15,7 @@ for dir in "${directories[@]}"; do
pushd "$dir" > /dev/null
sed -i.bak "/^client-api[[:alnum:]-]*[[:space:]]*=/s/rev = \"[a-fA-F0-9]\{6,40\}\"/rev = \"$NEW_REV\"/g" Cargo.toml
sed -i.bak '/^workspace-template *=/ s/rev = "[a-fA-F0-9]\{6,40\}"/rev = "'"$NEW_REV"'"/' Cargo.toml
# Detect changed crates
client_api_crates=($(grep -E '^client-api[a-zA-Z0-9_-]* =' Cargo.toml | awk -F'=' '{print $1}' | tr -d ' '))