refactor(server): move asset detail endpoint to new controller (#6636)

* refactor(server): move asset by id to new controller

* chore: open api

* refactor: more consolidation

* refactor: asset service
This commit is contained in:
Jason Rasmussen 2024-01-25 12:52:21 -05:00 committed by GitHub
parent 19d4c5e9f7
commit b306cf564e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 541 additions and 174 deletions

View file

@ -15,7 +15,6 @@ import {
IAccessRepository,
IAssetRepository,
ICommunicationRepository,
ICryptoRepository,
IJobRepository,
IPartnerRepository,
IStorageRepository,
@ -87,7 +86,6 @@ export class AssetService {
constructor(
@Inject(IAccessRepository) accessRepository: IAccessRepository,
@Inject(IAssetRepository) private assetRepository: IAssetRepository,
@Inject(ICryptoRepository) private cryptoRepository: ICryptoRepository,
@Inject(IJobRepository) private jobRepository: IJobRepository,
@Inject(ISystemConfigRepository) configRepository: ISystemConfigRepository,
@Inject(IStorageRepository) private storageRepository: IStorageRepository,
@ -400,6 +398,44 @@ export class AssetService {
return this.assetRepository.getAllByDeviceId(auth.user.id, deviceId);
}
async get(auth: AuthDto, id: string): Promise<AssetResponseDto | SanitizedAssetResponseDto> {
await this.access.requirePermission(auth, Permission.ASSET_READ, id);
const asset = await this.assetRepository.getById(id, {
exifInfo: true,
tags: true,
sharedLinks: true,
smartInfo: true,
owner: true,
faces: {
person: true,
},
stack: {
exifInfo: true,
},
});
if (!asset) {
throw new BadRequestException('Asset not found');
}
if (auth.sharedLink && !auth.sharedLink.showExif) {
return mapAsset(asset, { stripMetadata: true, withStack: true });
}
const data = mapAsset(asset, { withStack: true });
if (auth.sharedLink) {
delete data.owner;
}
if (data.ownerId !== auth.user.id) {
data.people = [];
}
return data;
}
async update(auth: AuthDto, id: string, dto: UpdateAssetDto): Promise<AssetResponseDto> {
await this.access.requirePermission(auth, Permission.ASSET_UPDATE, id);