diff --git a/src/common/backend/services/notion/service.ts b/src/common/backend/services/notion/service.ts index d45e0de0..44c7b5de 100644 --- a/src/common/backend/services/notion/service.ts +++ b/src/common/backend/services/notion/service.ts @@ -81,8 +81,9 @@ export default class NotionDocumentService implements DocumentService { const result: Array = await Promise.all( Object.keys(spaces).map(async (p) => { const space = spaces[p]; - const recentPages = await this.getRecentPageVisits(space.value.id, userId); - return this.loadSpace(p, space.value.name, recentPages); + const recentPages = await this.getRecentPageVisits(space.spaceId, userId); + const spaceName = await this.getSpaceName(space.spaceId); + return this.loadSpace(space.spaceId, spaceName, recentPages); }) ); @@ -94,13 +95,40 @@ export default class NotionDocumentService implements DocumentService { const response = await this.requestWithCookie.post<{ users: { [id: string]: { + user_root: { + [id: string]: { + value: { + space_view_pointers: [ + { + id: string; + table: string; + spaceId: string; + } + ] + } + }; + } space: any; }; }; }>('/api/v3/getSpacesInitial'); - return response.data.users[userId].space; + return response.data.users[userId].user_root[userId].value.space_view_pointers; }; + getSpaceName = async (spaceId: string) => { + const response = await this.requestWithCookie.post<{ + results: [ + { + name: string; + } + ] + }>('api/v3/getPublicSpaceData', { + spaceIds: [spaceId], + type: 'space-ids' + }); + return response.data.results[0].name; + } + createDocument = async ({ repositoryId, title, @@ -136,6 +164,7 @@ export default class NotionDocumentService implements DocumentService { spaceId: spaceId, }, spaceId: spaceId, + signedToken: fileUrl.signedToken, }, }, }); @@ -152,7 +181,7 @@ export default class NotionDocumentService implements DocumentService { const userId = Object.keys(this.userContent.recordMap.notion_user)[0] as string; const spaces = (await this.getSpaces(userId)) as any; - return Object.keys(spaces)[0]; + return spaces[0].spaceId; }; createEmptyFile = async (repository: NotionRepository, title: string) => { @@ -161,6 +190,8 @@ export default class NotionDocumentService implements DocumentService { } const spaceId = await this.getSpaceId(); const documentId = generateUuid(); + const requestId = generateUuid(); + const inner_requestId = generateUuid(); const parentId = repository.id; const userId = Object.values(this.userContent.recordMap.notion_user)[0].value.id; const time = new Date().getDate(); @@ -271,8 +302,15 @@ export default class NotionDocumentService implements DocumentService { ]; } - await this.requestWithCookie.post('api/v3/submitTransaction', { - operations, + await this.requestWithCookie.post('api/v3/saveTransactionsFanout', { + requestId: requestId, + transactions: [ + { + id: inner_requestId, + operations: operations, + spaceId: spaceId, + } + ] }); return documentId; }; @@ -281,6 +319,7 @@ export default class NotionDocumentService implements DocumentService { const result = await this.requestWithCookie.post<{ url: string; signedPutUrl: string; + signedToken: string; }>('api/v3/getUploadFileUrl', { bucket: 'temporary', name: fileName,