Enhance DocumentSchema and MinioService for improved error handling and functionality. Update page index validation to check for undefined or null values. Introduce total page count retrieval in DocumentSchema and adjust senderId handling. Refactor MinioService to correctly read and parse document pages, ensuring robust object management. This update improves clarity and reliability in document synchronization processes.
This commit is contained in:
@@ -159,14 +159,16 @@ export class DocumentSchema extends PothosSchema {
|
||||
if (ctx.isSubscription) throw new Error('Not allowed')
|
||||
if (!ctx.http?.me?.id) throw new Error('User not found')
|
||||
if (!args.documentId) throw new Error('Document id not found')
|
||||
if (!args.pageIndex) throw new Error('Page index not found')
|
||||
if (args.pageIndex === undefined || args.pageIndex === null) throw new Error('Page index not found')
|
||||
const delta = await this.minio.getDocumentPage(args.documentId, args.pageIndex)
|
||||
if (!delta) throw new Error('Delta not found')
|
||||
const totalPage = await this.minio.countDocumentPages(args.documentId)
|
||||
return {
|
||||
documentId: args.documentId,
|
||||
pageIndex: args.pageIndex,
|
||||
delta,
|
||||
senderId: 'server',
|
||||
totalPage,
|
||||
senderId: ctx.http?.me?.id,
|
||||
eventType: DocumentEvent.CLIENT_REQUEST_SYNC,
|
||||
}
|
||||
},
|
||||
@@ -265,8 +267,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
const senderId = ctx.http?.me?.id
|
||||
if (!args.data.documentId) throw new Error('Document id not found')
|
||||
if (!senderId) throw new Error('User not found')
|
||||
if (!args.data.pageIndex) throw new Error('Page index not found')
|
||||
|
||||
if (args.data.pageIndex === undefined || args.data.pageIndex === null) throw new Error('Page index not found')
|
||||
// save delta to minio
|
||||
const delta = args.data.delta
|
||||
if (!delta) throw new Error('Delta not found')
|
||||
@@ -275,7 +276,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
return {
|
||||
...args.data,
|
||||
totalPage,
|
||||
senderId,
|
||||
senderId: 'server',
|
||||
eventType: DocumentEvent.SERVER_REQUEST_SYNC,
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user