Fix missing encoding in workspace-logo, members, person (#6510)

This commit is contained in:
Weiko
2024-08-02 15:18:48 +02:00
committed by GitHub
parent 0c036efcc4
commit 5870979bfa
13 changed files with 176 additions and 70 deletions

View File

@ -1,15 +1,15 @@
import { Module } from '@nestjs/common';
import { forwardRef, Module } from '@nestjs/common';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FilePathGuard } from 'src/engine/core-modules/file/guards/file-path-guard';
import { AuthModule } from 'src/engine/core-modules/auth/auth.module';
import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';
import { FilePathGuard } from 'src/engine/core-modules/file/guards/file-path-guard';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FileService } from './services/file.service';
import { FileController } from './controllers/file.controller';
import { FileService } from './services/file.service';
@Module({
imports: [FileUploadModule, AuthModule],
imports: [FileUploadModule, forwardRef(() => AuthModule)],
providers: [FileService, EnvironmentService, FilePathGuard],
exports: [FileService],
controllers: [FileController],

View File

@ -1,5 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FileStorageService } from 'src/engine/integrations/file-storage/file-storage.service';
@ -20,6 +21,10 @@ describe('FileService', () => {
provide: EnvironmentService,
useValue: {},
},
{
provide: TokenService,
useValue: {},
},
],
}).compile();

View File

@ -2,16 +2,25 @@ import { Injectable } from '@nestjs/common';
import { Stream } from 'stream';
import { addMilliseconds } from 'date-fns';
import ms from 'ms';
import {
FileStorageException,
FileStorageExceptionCode,
} from 'src/engine/integrations/file-storage/interfaces/file-storage-exception';
import { TokenService } from 'src/engine/core-modules/auth/services/token.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
import { FileStorageService } from 'src/engine/integrations/file-storage/file-storage.service';
@Injectable()
export class FileService {
constructor(private readonly fileStorageService: FileStorageService) {}
constructor(
private readonly fileStorageService: FileStorageService,
private readonly environmentService: EnvironmentService,
private readonly tokenService: TokenService,
) {}
async getFileStream(
folderPath: string,
@ -39,4 +48,25 @@ export class FileService {
throw error;
}
}
async encodeFileToken(payloadToEncode: Record<string, any>) {
const fileTokenExpiresIn = this.environmentService.get(
'FILE_TOKEN_EXPIRES_IN',
);
const secret = this.environmentService.get('FILE_TOKEN_SECRET');
const expirationDate = addMilliseconds(new Date(), ms(fileTokenExpiresIn));
const signedPayload = await this.tokenService.encodePayload(
{
expiration_date: expirationDate,
...payloadToEncode,
},
{
secret,
},
);
return signedPayload;
}
}