mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
refactor(server): do not force init binary when creating workspace (#5146)
This commit is contained in:
@@ -25,7 +25,6 @@ import {
|
|||||||
EventError,
|
EventError,
|
||||||
InternalError,
|
InternalError,
|
||||||
NotInWorkspaceError,
|
NotInWorkspaceError,
|
||||||
WorkspaceNotFoundError,
|
|
||||||
} from './error';
|
} from './error';
|
||||||
|
|
||||||
export const GatewayErrorWrapper = (): MethodDecorator => {
|
export const GatewayErrorWrapper = (): MethodDecorator => {
|
||||||
@@ -319,9 +318,7 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
|
|||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return {
|
return {
|
||||||
error: docId.isWorkspace
|
error: new DocNotFoundError(workspaceId, docId.guid),
|
||||||
? new WorkspaceNotFoundError(workspaceId)
|
|
||||||
: new DocNotFoundError(workspaceId, docId.guid),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -308,22 +308,11 @@ export class WorkspaceResolver {
|
|||||||
})
|
})
|
||||||
async createWorkspace(
|
async createWorkspace(
|
||||||
@CurrentUser() user: UserType,
|
@CurrentUser() user: UserType,
|
||||||
@Args({ name: 'init', type: () => GraphQLUpload })
|
// we no longer support init workspace with a preload file
|
||||||
update: FileUpload
|
// use sync system to uploading them once created
|
||||||
|
@Args({ name: 'init', type: () => GraphQLUpload, nullable: true })
|
||||||
|
init: FileUpload | null
|
||||||
) {
|
) {
|
||||||
// convert stream to buffer
|
|
||||||
const buffer = await new Promise<Buffer>((resolve, reject) => {
|
|
||||||
const stream = update.createReadStream();
|
|
||||||
const chunks: Uint8Array[] = [];
|
|
||||||
stream.on('data', chunk => {
|
|
||||||
chunks.push(chunk);
|
|
||||||
});
|
|
||||||
stream.on('error', reject);
|
|
||||||
stream.on('end', () => {
|
|
||||||
resolve(Buffer.concat(chunks));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const workspace = await this.prisma.workspace.create({
|
const workspace = await this.prisma.workspace.create({
|
||||||
data: {
|
data: {
|
||||||
public: false,
|
public: false,
|
||||||
@@ -341,14 +330,31 @@ export class WorkspaceResolver {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (buffer.length) {
|
if (init) {
|
||||||
await this.prisma.snapshot.create({
|
// convert stream to buffer
|
||||||
data: {
|
const buffer = await new Promise<Buffer>(resolve => {
|
||||||
id: workspace.id,
|
const stream = init.createReadStream();
|
||||||
workspaceId: workspace.id,
|
const chunks: Uint8Array[] = [];
|
||||||
blob: buffer,
|
stream.on('data', chunk => {
|
||||||
},
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
stream.on('error', () => {
|
||||||
|
resolve(Buffer.from([]));
|
||||||
|
});
|
||||||
|
stream.on('end', () => {
|
||||||
|
resolve(Buffer.concat(chunks));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (buffer.length) {
|
||||||
|
await this.prisma.snapshot.create({
|
||||||
|
data: {
|
||||||
|
id: workspace.id,
|
||||||
|
workspaceId: workspace.id,
|
||||||
|
blob: buffer,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ type Mutation {
|
|||||||
sendVerifyChangeEmail(token: String!, email: String!, callbackUrl: String!): Boolean!
|
sendVerifyChangeEmail(token: String!, email: String!, callbackUrl: String!): Boolean!
|
||||||
|
|
||||||
"""Create a new workspace"""
|
"""Create a new workspace"""
|
||||||
createWorkspace(init: Upload!): WorkspaceType!
|
createWorkspace(init: Upload): WorkspaceType!
|
||||||
|
|
||||||
"""Update workspace"""
|
"""Update workspace"""
|
||||||
updateWorkspace(input: UpdateWorkspaceInput!): WorkspaceType!
|
updateWorkspace(input: UpdateWorkspaceInput!): WorkspaceType!
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mutation createWorkspace($init: Upload!) {
|
mutation createWorkspace {
|
||||||
createWorkspace(init: $init) {
|
createWorkspace {
|
||||||
id
|
id
|
||||||
public
|
public
|
||||||
createdAt
|
createdAt
|
||||||
|
|||||||
@@ -153,10 +153,10 @@ export const createWorkspaceMutation = {
|
|||||||
id: 'createWorkspaceMutation' as const,
|
id: 'createWorkspaceMutation' as const,
|
||||||
operationName: 'createWorkspace',
|
operationName: 'createWorkspace',
|
||||||
definitionName: 'createWorkspace',
|
definitionName: 'createWorkspace',
|
||||||
containsFile: true,
|
containsFile: false,
|
||||||
query: `
|
query: `
|
||||||
mutation createWorkspace($init: Upload!) {
|
mutation createWorkspace {
|
||||||
createWorkspace(init: $init) {
|
createWorkspace {
|
||||||
id
|
id
|
||||||
public
|
public
|
||||||
createdAt
|
createdAt
|
||||||
|
|||||||
@@ -199,9 +199,7 @@ export type CreateCustomerPortalMutation = {
|
|||||||
createCustomerPortal: string;
|
createCustomerPortal: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CreateWorkspaceMutationVariables = Exact<{
|
export type CreateWorkspaceMutationVariables = Exact<{ [key: string]: never }>;
|
||||||
init: Scalars['Upload']['input'];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type CreateWorkspaceMutation = {
|
export type CreateWorkspaceMutation = {
|
||||||
__typename?: 'Mutation';
|
__typename?: 'Mutation';
|
||||||
|
|||||||
@@ -40,13 +40,8 @@ export const CRUD: WorkspaceCRUD<WorkspaceFlavour.AFFINE_CLOUD> = {
|
|||||||
}
|
}
|
||||||
const { createWorkspace } = await fetcher({
|
const { createWorkspace } = await fetcher({
|
||||||
query: createWorkspaceMutation,
|
query: createWorkspaceMutation,
|
||||||
variables: {
|
|
||||||
init: new File(
|
|
||||||
[Y.encodeStateAsUpdate(upstreamWorkspace.doc)],
|
|
||||||
'initBinary.yDoc'
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
createdWorkspaces.push(upstreamWorkspace.id);
|
createdWorkspaces.push(upstreamWorkspace.id);
|
||||||
const newBlockSuiteWorkspace = getOrCreateWorkspace(
|
const newBlockSuiteWorkspace = getOrCreateWorkspace(
|
||||||
createWorkspace.id,
|
createWorkspace.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user