From d1b0b64d598283b21ace51922cc58eb409eae2cf Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Wed, 7 Jun 2023 00:27:28 -0400 Subject: [PATCH] refactor(server): album download check (#2679) --- .../apps/immich/src/api-v1/album/album.controller.ts | 1 - .../immich/src/api-v1/album/album.service.spec.ts | 12 ++---------- server/apps/immich/src/api-v1/album/album.service.ts | 9 +++------ 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/server/apps/immich/src/api-v1/album/album.controller.ts b/server/apps/immich/src/api-v1/album/album.controller.ts index b84e807a8..49f8ec7d2 100644 --- a/server/apps/immich/src/api-v1/album/album.controller.ts +++ b/server/apps/immich/src/api-v1/album/album.controller.ts @@ -80,7 +80,6 @@ export class AlbumController { @Query() dto: DownloadDto, @Response({ passthrough: true }) res: Res, ) { - this.service.checkDownloadAccess(authUser); return this.service.downloadArchive(authUser, id, dto).then((download) => handleDownload(download, res)); } diff --git a/server/apps/immich/src/api-v1/album/album.service.spec.ts b/server/apps/immich/src/api-v1/album/album.service.spec.ts index 1b24ee8d5..84b9fad13 100644 --- a/server/apps/immich/src/api-v1/album/album.service.spec.ts +++ b/server/apps/immich/src/api-v1/album/album.service.spec.ts @@ -2,17 +2,12 @@ import { AlbumService } from './album.service'; import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common'; import { AlbumEntity, UserEntity } from '@app/infra/entities'; -import { AlbumResponseDto, ICryptoRepository, IJobRepository, mapUser } from '@app/domain'; +import { AlbumResponseDto, ICryptoRepository, mapUser } from '@app/domain'; import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; import { IAlbumRepository } from './album-repository'; import { DownloadService } from '../../modules/download/download.service'; import { ISharedLinkRepository } from '@app/domain'; -import { - newCryptoRepositoryMock, - newJobRepositoryMock, - newSharedLinkRepositoryMock, - userEntityStub, -} from '@app/domain/../test'; +import { newCryptoRepositoryMock, newSharedLinkRepositoryMock, userEntityStub } from '@app/domain/../test'; describe('Album service', () => { let sut: AlbumService; @@ -20,7 +15,6 @@ describe('Album service', () => { let sharedLinkRepositoryMock: jest.Mocked; let downloadServiceMock: jest.Mocked>; let cryptoMock: jest.Mocked; - let jobMock: jest.Mocked; const authUser: AuthUserDto = Object.freeze({ id: '1111', @@ -137,14 +131,12 @@ describe('Album service', () => { }; cryptoMock = newCryptoRepositoryMock(); - jobMock = newJobRepositoryMock(); sut = new AlbumService( albumRepositoryMock, sharedLinkRepositoryMock, downloadServiceMock as DownloadService, cryptoMock, - jobMock, ); }); diff --git a/server/apps/immich/src/api-v1/album/album.service.ts b/server/apps/immich/src/api-v1/album/album.service.ts index 63f8d61bc..f8e09eb27 100644 --- a/server/apps/immich/src/api-v1/album/album.service.ts +++ b/server/apps/immich/src/api-v1/album/album.service.ts @@ -3,7 +3,7 @@ import { AuthUserDto } from '../../decorators/auth-user.decorator'; import { AlbumEntity, SharedLinkType } from '@app/infra/entities'; import { AddUsersDto } from './dto/add-users.dto'; import { RemoveAssetsDto } from './dto/remove-assets.dto'; -import { AlbumResponseDto, IJobRepository, mapAlbum } from '@app/domain'; +import { AlbumResponseDto, mapAlbum } from '@app/domain'; import { IAlbumRepository } from './album-repository'; import { AlbumCountResponseDto } from './response-dto/album-count-response.dto'; import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; @@ -29,7 +29,6 @@ export class AlbumService { @Inject(ISharedLinkRepository) sharedLinkRepository: ISharedLinkRepository, private downloadService: DownloadService, @Inject(ICryptoRepository) cryptoRepository: ICryptoRepository, - @Inject(IJobRepository) private jobRepository: IJobRepository, ) { this.shareCore = new SharedLinkCore(sharedLinkRepository, cryptoRepository); } @@ -115,6 +114,8 @@ export class AlbumService { } async downloadArchive(authUser: AuthUserDto, albumId: string, dto: DownloadDto) { + this.shareCore.checkDownloadAccess(authUser); + const album = await this._getAlbum({ authUser, albumId, validateIsOwner: false }); const assets = (album.assets || []).map((asset) => asset).slice(dto.skip || 0); @@ -137,8 +138,4 @@ export class AlbumService { return mapSharedLink(sharedLink); } - - checkDownloadAccess(authUser: AuthUserDto) { - this.shareCore.checkDownloadAccess(authUser); - } }