diff --git a/packages/server/src/modules/document.module.ts b/packages/server/src/modules/document.module.ts index 50050a0..1240c9a 100644 --- a/packages/server/src/modules/document.module.ts +++ b/packages/server/src/modules/document.module.ts @@ -8,12 +8,14 @@ import { UserModule } from '@modules/user.module'; import { ViewModule } from '@modules/view.module'; import { WikiModule } from '@modules/wiki.module'; import { forwardRef, Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; import { TypeOrmModule } from '@nestjs/typeorm'; import { DocumentService } from '@services/document.service'; @Module({ imports: [ TypeOrmModule.forFeature([DocumentAuthorityEntity, DocumentEntity]), + forwardRef(() => ConfigModule), forwardRef(() => UserModule), forwardRef(() => WikiModule), forwardRef(() => MessageModule), diff --git a/packages/server/src/services/collaboration.service.ts b/packages/server/src/services/collaboration.service.ts index 8b9d8e0..91c2fa5 100644 --- a/packages/server/src/services/collaboration.service.ts +++ b/packages/server/src/services/collaboration.service.ts @@ -1,6 +1,7 @@ import { onAuthenticatePayload, onChangePayload, onLoadDocumentPayload, Server } from '@hocuspocus/server'; import { TiptapTransformer } from '@hocuspocus/transformer'; import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { DocumentService } from '@services/document.service'; import { DocumentVersionService } from '@services/document-version.service'; import { TemplateService } from '@services/template.service'; @@ -26,12 +27,18 @@ export class CollaborationService { constructor( @Inject(forwardRef(() => UserService)) private readonly userService: UserService, + @Inject(forwardRef(() => DocumentService)) private readonly documentService: DocumentService, + @Inject(forwardRef(() => TemplateService)) private readonly templateService: TemplateService, + @Inject(forwardRef(() => DocumentVersionService)) - private readonly documentVersionService: DocumentVersionService + private readonly documentVersionService: DocumentVersionService, + + @Inject(forwardRef(() => ConfigService)) + private readonly configService: ConfigService ) { this.initServer(); } @@ -73,8 +80,9 @@ export class CollaborationService { onDisconnect: this.onDisconnect.bind(this), }); this.server = server; - await this.server.listen(lodash.get(getConfig(), 'server.collaborationPort', 5003)); - console.log('[think] 协作服务启动成功'); + const port = this.configService.get('server.collaborationPort') || 5003; + await this.server.listen(port); + console.log(`[think] 协作服务启动成功,端口:${port}`); } catch (err) { console.error('[think] 协作服务启动失败:', err.message); } diff --git a/packages/server/src/services/document.service.ts b/packages/server/src/services/document.service.ts index dec2c17..3a1ab7d 100644 --- a/packages/server/src/services/document.service.ts +++ b/packages/server/src/services/document.service.ts @@ -5,6 +5,7 @@ import { UpdateDocumentDto } from '@dtos/update-document.dto'; import { DocumentEntity } from '@entities/document.entity'; import { DocumentAuthorityEntity } from '@entities/document-authority.entity'; import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import { InjectRepository } from '@nestjs/typeorm'; import { CollaborationService } from '@services/collaboration.service'; import { DocumentVersionService } from '@services/document-version.service'; @@ -30,6 +31,9 @@ export class DocumentService { @InjectRepository(DocumentEntity) public readonly documentRepo: Repository, + @Inject(forwardRef(() => ConfigService)) + private readonly configService: ConfigService, + @Inject(forwardRef(() => MessageService)) private readonly messageService: MessageService, @@ -50,7 +54,8 @@ export class DocumentService { this.userService, this, this.templateService, - this.documentVersionService + this.documentVersionService, + this.configService ); }