mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-24 04:27:27 +08:00
fix(server): hotfix auth & doc push (#6168)
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ModuleRef, Reflector } from '@nestjs/core';
|
import { ModuleRef, Reflector } from '@nestjs/core';
|
||||||
|
|
||||||
import { Config, getRequestResponseFromContext } from '../../fundamentals';
|
import { getRequestResponseFromContext } from '../../fundamentals';
|
||||||
import { AuthService, parseAuthUserSeqNum } from './service';
|
import { AuthService, parseAuthUserSeqNum } from './service';
|
||||||
|
|
||||||
function extractTokenFromHeader(authorization: string) {
|
function extractTokenFromHeader(authorization: string) {
|
||||||
@@ -27,7 +27,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
|
|||||||
private auth!: AuthService;
|
private auth!: AuthService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly config: Config,
|
|
||||||
private readonly ref: ModuleRef,
|
private readonly ref: ModuleRef,
|
||||||
private readonly reflector: Reflector
|
private readonly reflector: Reflector
|
||||||
) {}
|
) {}
|
||||||
@@ -43,17 +42,6 @@ export class AuthGuard implements CanActivate, OnModuleInit {
|
|||||||
let sessionToken: string | undefined =
|
let sessionToken: string | undefined =
|
||||||
req.cookies[AuthService.sessionCookieName];
|
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) {
|
if (!sessionToken && req.headers.authorization) {
|
||||||
sessionToken = extractTokenFromHeader(req.headers.authorization);
|
sessionToken = extractTokenFromHeader(req.headers.authorization);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,11 +272,15 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
updates: Buffer[],
|
updates: Buffer[],
|
||||||
retryTimes = 10
|
retryTimes = 10
|
||||||
) {
|
) {
|
||||||
const lastSeq = await this.getUpdateSeq(workspaceId, guid, updates.length);
|
const timestamp = await new Promise<number>((resolve, reject) => {
|
||||||
const now = Date.now();
|
|
||||||
let timestamp = now;
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
|
||||||
defer(async () => {
|
defer(async () => {
|
||||||
|
const lastSeq = await this.getUpdateSeq(
|
||||||
|
workspaceId,
|
||||||
|
guid,
|
||||||
|
updates.length
|
||||||
|
);
|
||||||
|
const now = Date.now();
|
||||||
|
let timestamp = now;
|
||||||
let turn = 0;
|
let turn = 0;
|
||||||
const batchCount = 10;
|
const batchCount = 10;
|
||||||
for (const batch of chunk(updates, batchCount)) {
|
for (const batch of chunk(updates, batchCount)) {
|
||||||
@@ -303,14 +307,16 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
|||||||
});
|
});
|
||||||
turn++;
|
turn++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return timestamp;
|
||||||
})
|
})
|
||||||
.pipe(retry(retryTimes)) // retry until seq num not conflict
|
.pipe(retry(retryTimes)) // retry until seq num not conflict
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next: () => {
|
next: timestamp => {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`pushed ${updates.length} updates for ${guid} in workspace ${workspaceId}`
|
`pushed ${updates.length} updates for ${guid} in workspace ${workspaceId}`
|
||||||
);
|
);
|
||||||
resolve();
|
resolve(timestamp);
|
||||||
},
|
},
|
||||||
error: e => {
|
error: e => {
|
||||||
this.logger.error('Failed to push updates', e);
|
this.logger.error('Failed to push updates', e);
|
||||||
|
|||||||
Reference in New Issue
Block a user