mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
feat: create user if not exist
This commit is contained in:
@@ -10,6 +10,7 @@ import { WorkspaceMeta, WorkspaceInfo } from '../../types';
|
||||
import { IPCBlobProvider } from './blocksuite-provider/blob.js';
|
||||
import { WorkspaceDetail } from '../affine/apis/workspace.js';
|
||||
import { setDefaultAvatar } from '../utils.js';
|
||||
import { User } from './ipc/types/user.js';
|
||||
|
||||
export class TauriIPCProvider extends LocalProvider {
|
||||
static id = 'tauri-ipc';
|
||||
@@ -18,6 +19,7 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
constructor(params: ProviderConstructorParams) {
|
||||
super(params);
|
||||
// TODO: let blocksuite's blob provider get blob receive workspace id. Currently, all blobs are placed together
|
||||
this.loadWorkspaces();
|
||||
}
|
||||
|
||||
async init() {
|
||||
@@ -111,7 +113,7 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
owner: undefined,
|
||||
isLocal: true,
|
||||
memberCount: 1,
|
||||
provider: 'affine',
|
||||
provider: this.id,
|
||||
};
|
||||
|
||||
if (!blocksuiteWorkspace.meta.avatar) {
|
||||
@@ -124,15 +126,29 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
|
||||
override async loadWorkspaces() {
|
||||
// TODO: get user id here
|
||||
// try create a default user, otherwise getWorkspaces will failed due to user not exists
|
||||
let createdUserID = 0;
|
||||
try {
|
||||
const user = await ipcMethods.createUser({
|
||||
email: 'xxx@xx.xx',
|
||||
name: 'xxx',
|
||||
password: 'xxx',
|
||||
avatar_url: '',
|
||||
});
|
||||
createdUserID = user.id;
|
||||
} catch (error) {
|
||||
// maybe user existed, which can be omited
|
||||
console.error(error);
|
||||
}
|
||||
const { workspaces: workspacesList } = await ipcMethods.getWorkspaces({
|
||||
user_id: 0,
|
||||
user_id: createdUserID,
|
||||
});
|
||||
const workspaces: WorkspaceInfo[] = workspacesList.map(w => {
|
||||
return {
|
||||
...w,
|
||||
memberCount: 0,
|
||||
name: '',
|
||||
provider: 'affine',
|
||||
provider: this.id,
|
||||
};
|
||||
});
|
||||
const workspaceInstances = workspaces.map(({ id }) => {
|
||||
|
||||
@@ -11,8 +11,10 @@ import {
|
||||
GetWorkspaceResult,
|
||||
GetWorkspaces,
|
||||
GetWorkspacesResult,
|
||||
User,
|
||||
} from './types/workspace';
|
||||
import { GetBlob, PutBlob } from './types/blob';
|
||||
import { CreateUser } from './types/user';
|
||||
|
||||
export const updateYDocument = async (parameters: YDocumentUpdate) =>
|
||||
await invoke<boolean>('update_y_document', {
|
||||
@@ -48,3 +50,8 @@ export const getBlob = async (parameters: GetBlob) =>
|
||||
await invoke<number[]>('get_blob', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const createUser = async (parameters: CreateUser) =>
|
||||
await invoke<User>('create_user', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "IUserParameters",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["CreateUser"],
|
||||
"properties": {
|
||||
"CreateUser": {
|
||||
"$ref": "#/definitions/CreateUser"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["User"],
|
||||
"properties": {
|
||||
"User": {
|
||||
"$ref": "#/definitions/User"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
],
|
||||
"definitions": {
|
||||
"CreateUser": {
|
||||
"type": "object",
|
||||
"required": ["email", "name", "password"],
|
||||
"properties": {
|
||||
"avatar_url": {
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"User": {
|
||||
"type": "object",
|
||||
"required": ["created_at", "email", "id", "name"],
|
||||
"properties": {
|
||||
"avatar_url": {
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
"created_at": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* tslint:disable */
|
||||
/**
|
||||
* This file was automatically generated by json-schema-to-typescript.
|
||||
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
||||
* and run json-schema-to-typescript to regenerate this file.
|
||||
*/
|
||||
|
||||
export type IUserParameters =
|
||||
| {
|
||||
CreateUser: CreateUser;
|
||||
}
|
||||
| {
|
||||
User: User;
|
||||
};
|
||||
|
||||
export interface CreateUser {
|
||||
avatar_url?: string | null;
|
||||
email: string;
|
||||
name: string;
|
||||
password: string;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface User {
|
||||
avatar_url?: string | null;
|
||||
created_at: number;
|
||||
email: string;
|
||||
id: number;
|
||||
name: string;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
Reference in New Issue
Block a user