mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-31 02:39:03 -04:00 
			
		
		
		
	refactor(server): album download check (#2679)
This commit is contained in:
		
							parent
							
								
									d0cc231782
								
							
						
					
					
						commit
						d1b0b64d59
					
				| @ -80,7 +80,6 @@ export class AlbumController { | |||||||
|     @Query() dto: DownloadDto, |     @Query() dto: DownloadDto, | ||||||
|     @Response({ passthrough: true }) res: Res, |     @Response({ passthrough: true }) res: Res, | ||||||
|   ) { |   ) { | ||||||
|     this.service.checkDownloadAccess(authUser); |  | ||||||
|     return this.service.downloadArchive(authUser, id, dto).then((download) => handleDownload(download, res)); |     return this.service.downloadArchive(authUser, id, dto).then((download) => handleDownload(download, res)); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,17 +2,12 @@ import { AlbumService } from './album.service'; | |||||||
| import { AuthUserDto } from '../../decorators/auth-user.decorator'; | import { AuthUserDto } from '../../decorators/auth-user.decorator'; | ||||||
| import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common'; | import { BadRequestException, NotFoundException, ForbiddenException } from '@nestjs/common'; | ||||||
| import { AlbumEntity, UserEntity } from '@app/infra/entities'; | 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 { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; | ||||||
| import { IAlbumRepository } from './album-repository'; | import { IAlbumRepository } from './album-repository'; | ||||||
| import { DownloadService } from '../../modules/download/download.service'; | import { DownloadService } from '../../modules/download/download.service'; | ||||||
| import { ISharedLinkRepository } from '@app/domain'; | import { ISharedLinkRepository } from '@app/domain'; | ||||||
| import { | import { newCryptoRepositoryMock, newSharedLinkRepositoryMock, userEntityStub } from '@app/domain/../test'; | ||||||
|   newCryptoRepositoryMock, |  | ||||||
|   newJobRepositoryMock, |  | ||||||
|   newSharedLinkRepositoryMock, |  | ||||||
|   userEntityStub, |  | ||||||
| } from '@app/domain/../test'; |  | ||||||
| 
 | 
 | ||||||
| describe('Album service', () => { | describe('Album service', () => { | ||||||
|   let sut: AlbumService; |   let sut: AlbumService; | ||||||
| @ -20,7 +15,6 @@ describe('Album service', () => { | |||||||
|   let sharedLinkRepositoryMock: jest.Mocked<ISharedLinkRepository>; |   let sharedLinkRepositoryMock: jest.Mocked<ISharedLinkRepository>; | ||||||
|   let downloadServiceMock: jest.Mocked<Partial<DownloadService>>; |   let downloadServiceMock: jest.Mocked<Partial<DownloadService>>; | ||||||
|   let cryptoMock: jest.Mocked<ICryptoRepository>; |   let cryptoMock: jest.Mocked<ICryptoRepository>; | ||||||
|   let jobMock: jest.Mocked<IJobRepository>; |  | ||||||
| 
 | 
 | ||||||
|   const authUser: AuthUserDto = Object.freeze({ |   const authUser: AuthUserDto = Object.freeze({ | ||||||
|     id: '1111', |     id: '1111', | ||||||
| @ -137,14 +131,12 @@ describe('Album service', () => { | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     cryptoMock = newCryptoRepositoryMock(); |     cryptoMock = newCryptoRepositoryMock(); | ||||||
|     jobMock = newJobRepositoryMock(); |  | ||||||
| 
 | 
 | ||||||
|     sut = new AlbumService( |     sut = new AlbumService( | ||||||
|       albumRepositoryMock, |       albumRepositoryMock, | ||||||
|       sharedLinkRepositoryMock, |       sharedLinkRepositoryMock, | ||||||
|       downloadServiceMock as DownloadService, |       downloadServiceMock as DownloadService, | ||||||
|       cryptoMock, |       cryptoMock, | ||||||
|       jobMock, |  | ||||||
|     ); |     ); | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ import { AuthUserDto } from '../../decorators/auth-user.decorator'; | |||||||
| import { AlbumEntity, SharedLinkType } from '@app/infra/entities'; | import { AlbumEntity, SharedLinkType } from '@app/infra/entities'; | ||||||
| import { AddUsersDto } from './dto/add-users.dto'; | import { AddUsersDto } from './dto/add-users.dto'; | ||||||
| import { RemoveAssetsDto } from './dto/remove-assets.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 { IAlbumRepository } from './album-repository'; | ||||||
| import { AlbumCountResponseDto } from './response-dto/album-count-response.dto'; | import { AlbumCountResponseDto } from './response-dto/album-count-response.dto'; | ||||||
| import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; | import { AddAssetsResponseDto } from './response-dto/add-assets-response.dto'; | ||||||
| @ -29,7 +29,6 @@ export class AlbumService { | |||||||
|     @Inject(ISharedLinkRepository) sharedLinkRepository: ISharedLinkRepository, |     @Inject(ISharedLinkRepository) sharedLinkRepository: ISharedLinkRepository, | ||||||
|     private downloadService: DownloadService, |     private downloadService: DownloadService, | ||||||
|     @Inject(ICryptoRepository) cryptoRepository: ICryptoRepository, |     @Inject(ICryptoRepository) cryptoRepository: ICryptoRepository, | ||||||
|     @Inject(IJobRepository) private jobRepository: IJobRepository, |  | ||||||
|   ) { |   ) { | ||||||
|     this.shareCore = new SharedLinkCore(sharedLinkRepository, cryptoRepository); |     this.shareCore = new SharedLinkCore(sharedLinkRepository, cryptoRepository); | ||||||
|   } |   } | ||||||
| @ -115,6 +114,8 @@ export class AlbumService { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async downloadArchive(authUser: AuthUserDto, albumId: string, dto: DownloadDto) { |   async downloadArchive(authUser: AuthUserDto, albumId: string, dto: DownloadDto) { | ||||||
|  |     this.shareCore.checkDownloadAccess(authUser); | ||||||
|  | 
 | ||||||
|     const album = await this._getAlbum({ authUser, albumId, validateIsOwner: false }); |     const album = await this._getAlbum({ authUser, albumId, validateIsOwner: false }); | ||||||
|     const assets = (album.assets || []).map((asset) => asset).slice(dto.skip || 0); |     const assets = (album.assets || []).map((asset) => asset).slice(dto.skip || 0); | ||||||
| 
 | 
 | ||||||
| @ -137,8 +138,4 @@ export class AlbumService { | |||||||
| 
 | 
 | ||||||
|     return mapSharedLink(sharedLink); |     return mapSharedLink(sharedLink); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   checkDownloadAccess(authUser: AuthUserDto) { |  | ||||||
|     this.shareCore.checkDownloadAccess(authUser); |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user