mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
fix: user id is now string, we need to get default on local
This commit is contained in:
@@ -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: 'xxx@xxx.xxx',
|
||||
name: 'xxx',
|
||||
};
|
||||
|
||||
@@ -21,10 +21,11 @@ import { applyUpdate } from '../../utils/index.js';
|
||||
*/
|
||||
export class TauriIPCProvider extends LocalProvider {
|
||||
static id = 'tauri-ipc';
|
||||
static defaultUserEmail = 'xxx@xx.xx';
|
||||
/**
|
||||
* // 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: 'xxx@xx.xx',
|
||||
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) => {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user