There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix: user id is now string, we need to get default on local
linonetwo483d1d67c6a6
diff --git a/client-app/src-tauri/src/commands.rs b/client-app/src-tauri/src/commands.rsindex 60ac58e04e..18523a06b2 100644--- a/client-app/src-tauri/src/commands.rs+++ b/client-app/src-tauri/src/commands.rs@@ -16,6 +16,7 @@ pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {get_workspaces,get_workspace,create_user,+ get_user,create_doc,get_doc,put_blob,diff --git a/client-app/src-tauri/src/commands/user.rs b/client-app/src-tauri/src/commands/user.rsindex c754e07aea..d18ede1617 100644--- a/client-app/src-tauri/src/commands/user.rs+++ b/client-app/src-tauri/src/commands/user.rs@@ -1,5 +1,5 @@use cloud_database::{CreateUser, User};-use ipc_types::document::CreateDocumentParameter;+use ipc_types::{document::CreateDocumentParameter, user::GetUserParameters};use crate::state::AppState;@@ -18,7 +18,7 @@ pub async fn create_user<'s>(.metadata_db.create_user(parameters.clone()).await;- match new_user_result{+ match new_user_result {Ok(new_user_option) => match new_user_option {Some((new_user, new_workspace)) => {// a new private workspace is created, we have to create a yDoc for it@@ -38,3 +38,16 @@ pub async fn create_user<'s>(Err(error_message) => Err(error_message.to_string()),}}++#[tauri::command]+/// get the only one user in local sqlite+pub async fn get_user<'s>(+ state: tauri::State<'s, AppState>,+ parameters: GetUserParameters,+) -> Result<User, String> {+ let db = &state.0.lock().await.metadata_db;+ match db.get_user_by_email(¶meters.email).await.ok().unwrap() {+ Some(user) => Ok(user),+ None => Err("User not found".to_string()),+ }+}diff --git a/client-app/src-tauri/types/src/user.rs b/client-app/src-tauri/types/src/user.rsindex 40b90751aa..63d7055d22 100644--- a/client-app/src-tauri/types/src/user.rs+++ b/client-app/src-tauri/types/src/user.rs@@ -2,8 +2,14 @@ use cloud_database::{CreateUser, User};use schemars::JsonSchema;use serde::{Deserialize, Serialize};+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]+pub struct GetUserParameters {+ pub email: String,+}+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]pub enum IUserParameters {CreateUser(CreateUser),User(User),+ GetUserParameters(GetUserParameters),}diff --git a/client-app/src-tauri/types/src/workspace.rs b/client-app/src-tauri/types/src/workspace.rsindex 2aca972bba..88b92477c4 100644--- a/client-app/src-tauri/types/src/workspace.rs+++ b/client-app/src-tauri/types/src/workspace.rs@@ -14,8 +14,7 @@ pub struct CreateWorkspace {#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]pub struct GetWorkspaces {- // TODO: make all id string, on Octobase side, and rewrite all related tests- pub user_id: i32,+ pub user_id: String,}#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]diff --git a/packages/data-center/src/provider/tauri-ipc/__tests__/mock-apis.ts b/packages/data-center/src/provider/tauri-ipc/__tests__/mock-apis.tsindex 9a17a4f161..f426a5c7c3 100644--- a/packages/data-center/src/provider/tauri-ipc/__tests__/mock-apis.ts+++ b/packages/data-center/src/provider/tauri-ipc/__tests__/mock-apis.ts@@ -61,7 +61,7 @@ export const getBlob = async (parameters: GetBlob): Promise<number[]> =>export const createUser = async (parameters: CreateUser): Promise<User> =>await {created_at: 0,- id: 1,+ id: '1',email: '[email protected]',name: 'xxx',};diff --git a/packages/data-center/src/provider/tauri-ipc/index.ts b/packages/data-center/src/provider/tauri-ipc/index.tsindex 024d39c0f1..1108dddbaf 100644--- a/packages/data-center/src/provider/tauri-ipc/index.ts+++ b/packages/data-center/src/provider/tauri-ipc/index.ts@@ -21,10 +21,11 @@ import { applyUpdate } from '../../utils/index.js';*/export class TauriIPCProvider extends LocalProvider {static id = 'tauri-ipc';+ static defaultUserEmail = '[email protected]';/*** // TODO: We only have one user in this version of app client. But may support switch user later.*/- #defaultUserID = 1;+ #userID?: string;#ipc: IPCMethodsType | undefined;constructor(params: ProviderConstructorParams) {@@ -37,18 +38,25 @@ export class TauriIPCProvider extends LocalProvider {} else {this.#ipc = await import('./ipc/methods.js');}- // we create a default user if we don't have one.try {- const user = await this.#ipc?.createUser({- email: '[email protected]',- name: 'xxx',- password: 'xxx',- avatar_url: '',+ const user = await this.#ipc?.getUser({+ email: TauriIPCProvider.defaultUserEmail,});- this.#defaultUserID = user.id;+ this.#userID = user.id;} catch (error) {- // maybe user existed, which can be omited- console.error(error);+ // maybe user not existed, we create a default user if we don't have one.+ try {+ const user = await this.#ipc?.createUser({+ email: TauriIPCProvider.defaultUserEmail,+ name: 'xxx',+ password: 'xxx',+ avatar_url: '',+ });+ this.#userID = user.id;+ } catch (error) {+ // maybe user existed, which can be omited+ console.error(error);+ }}}@@ -116,7 +124,7 @@ export class TauriIPCProvider extends LocalProvider {const { id } = await this.#ipc.createWorkspace({name: meta.name,// TODO: get userID here- user_id: this.#defaultUserID,+ user_id: this.#userID,});const workspaceUnit = await createWorkspaceUnit({@@ -144,7 +152,7 @@ export class TauriIPCProvider extends LocalProvider {override async loadWorkspaces(): Promise<WorkspaceUnit[]> {assert(this.#ipc);const { workspaces } = await this.#ipc.getWorkspaces({- user_id: this.#defaultUserID,+ user_id: this.#userID,});const workspaceUnits = await Promise.all(workspaces.map((meta: WorkspaceWithPermission) => {diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts b/packages/data-center/src/provider/tauri-ipc/ipc/methods.tsindex 6bb4f92c92..65cda5092e 100644--- a/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts+++ b/packages/data-center/src/provider/tauri-ipc/ipc/methods.ts@@ -14,7 +14,7 @@ import {User,} from './types/workspace';import { GetBlob, PutBlob } from './types/blob';-import { CreateUser } from './types/user';+import { CreateUser, GetUserParameters } from './types/user';export interface IPCMethodsType {updateYDocument: typeof updateYDocument;@@ -25,6 +25,7 @@ export interface IPCMethodsType {putBlob: typeof putBlob;getBlob: typeof getBlob;createUser: typeof createUser;+ getUser: typeof getUser;}export const updateYDocument = async (parameters: YDocumentUpdate) =>@@ -70,3 +71,8 @@ export const createUser = async (parameters: CreateUser) =>await invoke<User>('create_user', {parameters,});++export const getUser = async (parameters: GetUserParameters) =>+ await invoke<User>('get_user', {+ parameters,+ });diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/user.json b/packages/data-center/src/provider/tauri-ipc/ipc/types/user.jsonindex ae91d63e0f..9b3f54ec4f 100644--- a/packages/data-center/src/provider/tauri-ipc/ipc/types/user.json+++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/user.json@@ -21,6 +21,16 @@}},"additionalProperties": false+ },+ {+ "type": "object",+ "required": ["GetUserParameters"],+ "properties": {+ "GetUserParameters": {+ "$ref": "#/definitions/GetUserParameters"+ }+ },+ "additionalProperties": false}],"definitions": {@@ -42,6 +52,15 @@}}},+ "GetUserParameters": {+ "type": "object",+ "required": ["email"],+ "properties": {+ "email": {+ "type": "string"+ }+ }+ },"User": {"type": "object","required": ["created_at", "email", "id", "name"],@@ -57,8 +76,7 @@"type": "string"},"id": {- "type": "integer",- "format": "int32"+ "type": "string"},"name": {"type": "string"diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/user.ts b/packages/data-center/src/provider/tauri-ipc/ipc/types/user.tsindex 818b9d20b9..b03c418a64 100644--- a/packages/data-center/src/provider/tauri-ipc/ipc/types/user.ts+++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/user.ts@@ -10,6 +10,9 @@ export type IUserParameters =}| {User: User;+ }+ | {+ GetUserParameters: GetUserParameters;};export interface CreateUser {@@ -23,7 +26,11 @@ export interface User {avatar_url?: string | null;created_at: number;email: string;- id: number;+ id: string;name: string;[k: string]: unknown;}+export interface GetUserParameters {+ email: string;+ [k: string]: unknown;+}diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.jsonindex 26afd9e32d..9bfe0226ac 100644--- a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json+++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.json@@ -123,8 +123,7 @@"required": ["user_id"],"properties": {"user_id": {- "type": "integer",- "format": "int32"+ "type": "string"}}},@@ -172,8 +171,7 @@"type": "string"},"id": {- "type": "integer",- "format": "int32"+ "type": "string"},"name": {"type": "string"diff --git a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.tsindex 138af13c95..d7bacee60b 100644--- a/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts+++ b/packages/data-center/src/provider/tauri-ipc/ipc/types/workspace.ts@@ -42,7 +42,7 @@ export interface GetWorkspace {[k: string]: unknown;}export interface GetWorkspaces {- user_id: number;+ user_id: string;[k: string]: unknown;}export interface GetWorkspaceResult {@@ -62,7 +62,7 @@ export interface User {avatar_url?: string | null;created_at: number;email: string;- id: number;+ id: string;name: string;[k: string]: unknown;}