Skip to content

Commit

Permalink
fix: file names on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Jul 25, 2024
1 parent 993b10b commit 60be48e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/modules/file/file.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export class FileUseCases {
status: FileStatus.EXISTS,
});

const cryptoFileName = this.cryptoService.encryptName(
newFileDto.plainName,
folder.id,
);

const fileAlreadyExists = !!maybeAlreadyExistentFile;

if (fileAlreadyExists) {
Expand All @@ -115,7 +120,7 @@ export class FileUseCases {

const newFile = await this.fileRepository.create({
uuid: v4(),
name: newFileDto.name,
name: cryptoFileName,
plainName: newFileDto.plainName,
type: newFileDto.type,
size: newFileDto.size,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/workspaces/workspaces.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { FileModule } from '../file/file.module';
import { SharingModule } from '../sharing/sharing.module';
import { PaymentsService } from 'src/externals/payments/payments.service';
import { HttpClientModule } from 'src/externals/http/http.module';
import { CryptoModule } from '../../externals/crypto/crypto.module';

@Module({
imports: [
Expand All @@ -35,6 +36,7 @@ import { HttpClientModule } from 'src/externals/http/http.module';
forwardRef(() => FolderModule),
forwardRef(() => FileModule),
forwardRef(() => SharingModule),
CryptoModule,
BridgeModule,
MailerModule,
HttpClientModule,
Expand Down
19 changes: 15 additions & 4 deletions src/modules/workspaces/workspaces.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { WorkspaceItemUser } from './domains/workspace-item-user.domain';
import { SharingService } from '../sharing/sharing.service';
import { ChangeUserAssignedSpaceDto } from './dto/change-user-assigned-space.dto';
import { PaymentsService } from '../../externals/payments/payments.service';
import { CryptoService } from '../../externals/crypto/crypto.service';

@Injectable()
export class WorkspacesUsecases {
Expand All @@ -74,6 +75,7 @@ export class WorkspacesUsecases {
private readonly sharingUseCases: SharingService,
private readonly paymentService: PaymentsService,
private networkService: BridgeService,
private cryptoService: CryptoService,
private userRepository: SequelizeUserRepository,
private userUsecases: UserUseCases,
private configService: ConfigService,
Expand Down Expand Up @@ -700,7 +702,11 @@ export class WorkspacesUsecases {
itemType: WorkspaceItemType.Folder,
});

if (!parentFolder) {
const folder = await this.folderUseCases.getByUuid(
createFileDto.folderUuid,
);

if (!parentFolder || !folder) {
throw new BadRequestException('Parent folder is not valid');
}

Expand All @@ -715,11 +721,16 @@ export class WorkspacesUsecases {
workspace.workspaceUserId,
);

const createdFile = await this.fileUseCases.createFile(
networkUser,
createFileDto,
const cryptoFileName = this.cryptoService.encryptName(
createFileDto.plainName,
folder.id,
);

const createdFile = await this.fileUseCases.createFile(networkUser, {
...createFileDto,
name: cryptoFileName,
});

const createdItemFile = await this.workspaceRepository.createItem({
itemId: createdFile.uuid,
workspaceId,
Expand Down

0 comments on commit 60be48e

Please sign in to comment.