From a721b3887ba4b9de9064e05bf240414e5b30bd7d Mon Sep 17 00:00:00 2001 From: liuyi Date: Mon, 18 Mar 2024 16:22:47 +0800 Subject: [PATCH] fix(server): hotfix auth & doc push (#6168) --- packages/backend/server/src/core/auth/guard.ts | 14 +------------- .../backend/server/src/core/doc/manager.ts | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/backend/server/src/core/auth/guard.ts b/packages/backend/server/src/core/auth/guard.ts index d1ff3ab89d9fb..a60822001e13c 100644 --- a/packages/backend/server/src/core/auth/guard.ts +++ b/packages/backend/server/src/core/auth/guard.ts @@ -11,7 +11,7 @@ import { } from '@nestjs/common'; import { ModuleRef, Reflector } from '@nestjs/core'; -import { Config, getRequestResponseFromContext } from '../../fundamentals'; +import { getRequestResponseFromContext } from '../../fundamentals'; import { AuthService, parseAuthUserSeqNum } from './service'; function extractTokenFromHeader(authorization: string) { @@ -27,7 +27,6 @@ export class AuthGuard implements CanActivate, OnModuleInit { private auth!: AuthService; constructor( - private readonly config: Config, private readonly ref: ModuleRef, private readonly reflector: Reflector ) {} @@ -43,17 +42,6 @@ export class AuthGuard implements CanActivate, OnModuleInit { let sessionToken: string | undefined = req.cookies[AuthService.sessionCookieName]; - // backward compatibility for client older then 0.12 - // TODO: remove - if (!sessionToken) { - sessionToken = - req.cookies[ - this.config.https - ? '__Secure-next-auth.session-token' - : 'next-auth.session-token' - ]; - } - if (!sessionToken && req.headers.authorization) { sessionToken = extractTokenFromHeader(req.headers.authorization); } diff --git a/packages/backend/server/src/core/doc/manager.ts b/packages/backend/server/src/core/doc/manager.ts index faa50ecc7dba8..87c09fd8269a5 100644 --- a/packages/backend/server/src/core/doc/manager.ts +++ b/packages/backend/server/src/core/doc/manager.ts @@ -272,11 +272,15 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { updates: Buffer[], retryTimes = 10 ) { - const lastSeq = await this.getUpdateSeq(workspaceId, guid, updates.length); - const now = Date.now(); - let timestamp = now; - await new Promise((resolve, reject) => { + const timestamp = await new Promise((resolve, reject) => { defer(async () => { + const lastSeq = await this.getUpdateSeq( + workspaceId, + guid, + updates.length + ); + const now = Date.now(); + let timestamp = now; let turn = 0; const batchCount = 10; for (const batch of chunk(updates, batchCount)) { @@ -303,14 +307,16 @@ export class DocManager implements OnModuleInit, OnModuleDestroy { }); turn++; } + + return timestamp; }) .pipe(retry(retryTimes)) // retry until seq num not conflict .subscribe({ - next: () => { + next: timestamp => { this.logger.debug( `pushed ${updates.length} updates for ${guid} in workspace ${workspaceId}` ); - resolve(); + resolve(timestamp); }, error: e => { this.logger.error('Failed to push updates', e);