feat(server): get asset ids

This commit is contained in:
Jason Rasmussen 2023-09-05 21:05:33 -04:00
parent 454737ca79
commit 9569863609
No known key found for this signature in database
GPG key ID: 75AD31BF84C94773
10 changed files with 85 additions and 45 deletions

View file

@ -1325,6 +1325,51 @@
]
}
},
"/asset/ids": {
"get": {
"operationId": "getAssetIds",
"parameters": [
{
"name": "deviceId",
"required": true,
"in": "query",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"description": ""
}
},
"security": [
{
"bearer": []
},
{
"cookie": []
},
{
"api_key": []
}
],
"tags": [
"Asset"
]
}
},
"/asset/import": {
"post": {
"operationId": "importFile",
@ -1974,7 +2019,6 @@
},
"/asset/{deviceId}": {
"get": {
"description": "Get all asset of a device that are in the database, ID only.",
"operationId": "getUserAssetsByDeviceId",
"parameters": [
{

View file

@ -73,6 +73,7 @@ export interface IAssetRepository {
getByIds(ids: string[]): Promise<AssetEntity[]>;
getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity>;
getByUserId(pagination: PaginationOptions, userId: string): Paginated<AssetEntity>;
getByDeviceId(ownerId: string, deviceId: string): Promise<string[]>;
getWithout(pagination: PaginationOptions, property: WithoutProperty): Paginated<AssetEntity>;
getWith(pagination: PaginationOptions, property: WithProperty): Paginated<AssetEntity>;
getFirstAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;

View file

@ -17,6 +17,7 @@ import {
AssetJobName,
AssetJobsDto,
AssetStatsDto,
DeviceIdDto,
DownloadArchiveInfo,
DownloadInfoDto,
DownloadResponseDto,
@ -179,6 +180,10 @@ export class AssetService {
return assets.map(mapAsset);
}
getAssetIds(authUser: AuthUserDto, dto: DeviceIdDto) {
return this.assetRepository.getByDeviceId(authUser.id, dto.deviceId);
}
async downloadFile(authUser: AuthUserDto, id: string): Promise<ImmichReadStream> {
await this.access.requirePermission(authUser, Permission.ASSET_DOWNLOAD, id);

View file

@ -1,5 +1,5 @@
import { IsBoolean, IsString } from 'class-validator';
import { Optional } from '../../domain.util';
import { Optional, ValidateUUID } from '../../domain.util';
import { BulkIdsDto } from '../response-dto';
export class AssetBulkUpdateDto extends BulkIdsDto {
@ -25,3 +25,8 @@ export class UpdateAssetDto {
@IsString()
description?: string;
}
export class DeviceIdDto {
@ValidateUUID()
deviceId!: string;
}

View file

@ -26,7 +26,6 @@ export interface IAssetRepository {
): Promise<AssetEntity>;
remove(asset: AssetEntity): Promise<void>;
getAllByUserId(userId: string, dto: AssetSearchDto): Promise<AssetEntity[]>;
getAllByDeviceId(userId: string, deviceId: string): Promise<string[]>;
getById(assetId: string): Promise<AssetEntity>;
getLocationsByUserId(userId: string): Promise<CuratedLocationsResponseDto[]>;
getDetectedObjectsByUserId(userId: string): Promise<CuratedObjectsResponseDto[]>;
@ -159,26 +158,6 @@ export class AssetRepository implements IAssetRepository {
await this.assetRepository.remove(asset);
}
/**
* Get assets by device's Id on the database
* @param ownerId
* @param deviceId
*
* @returns Promise<string[]> - Array of assetIds belong to the device
*/
async getAllByDeviceId(ownerId: string, deviceId: string): Promise<string[]> {
const items = await this.assetRepository.find({
select: { deviceAssetId: true },
where: {
ownerId,
deviceId,
isVisible: true,
},
});
return items.map((asset) => asset.deviceAssetId);
}
/**
* Get assets by checksums on the database
* @param ownerId

View file

@ -28,7 +28,6 @@ import { CheckDuplicateAssetDto } from './dto/check-duplicate-asset.dto';
import { CheckExistingAssetsDto } from './dto/check-existing-assets.dto';
import { CreateAssetDto, ImportAssetDto } from './dto/create-asset.dto';
import { DeleteAssetDto } from './dto/delete-asset.dto';
import { DeviceIdDto } from './dto/device-id.dto';
import { GetAssetThumbnailDto } from './dto/get-asset-thumbnail.dto';
import { SearchAssetDto } from './dto/search-asset.dto';
import { ServeFileDto } from './dto/serve-file.dto';
@ -175,14 +174,6 @@ export class AssetController {
return this.assetService.getAllAssets(authUser, dto);
}
/**
* Get all asset of a device that are in the database, ID only.
*/
@Get('/:deviceId')
getUserAssetsByDeviceId(@AuthUser() authUser: AuthUserDto, @Param() { deviceId }: DeviceIdDto) {
return this.assetService.getUserAssetsByDeviceId(authUser, deviceId);
}
/**
* Get a single asset's information
*/

View file

@ -177,10 +177,6 @@ export class AssetService {
}
}
public async getUserAssetsByDeviceId(authUser: AuthUserDto, deviceId: string) {
return this._assetRepository.getAllByDeviceId(authUser.id, deviceId);
}
public async getAllAssets(authUser: AuthUserDto, dto: AssetSearchDto): Promise<AssetResponseDto[]> {
const userId = dto.userId || authUser.id;
await this.access.requirePermission(authUser, Permission.LIBRARY_READ, userId);

View file

@ -1,9 +0,0 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsUUID } from 'class-validator';
export class DeviceIdDto {
@IsNotEmpty()
@IsUUID('4')
@ApiProperty({ format: 'uuid' })
deviceId!: string;
}

View file

@ -7,6 +7,7 @@ import {
AssetStatsDto,
AssetStatsResponseDto,
AuthUserDto,
DeviceIdDto,
DownloadInfoDto,
DownloadResponseDto,
MapMarkerDto,
@ -80,6 +81,19 @@ export class AssetController {
return this.service.getByTimeBucket(authUser, dto);
}
@Get('ids')
getAssetIds(@AuthUser() authUser: AuthUserDto, @Query() dto: DeviceIdDto) {
return this.service.getAssetIds(authUser, dto);
}
/**
* @deprecated use `getAssetIds`
*/
@Get(':deviceId')
getUserAssetsByDeviceId(@AuthUser() authUser: AuthUserDto, @Param() dto: DeviceIdDto) {
return this.service.getAssetIds(authUser, dto);
}
@Post('jobs')
@HttpCode(HttpStatus.NO_CONTENT)
runAssetJobs(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetJobsDto): Promise<void> {

View file

@ -85,6 +85,20 @@ export class AssetRepository implements IAssetRepository {
},
});
}
async getByDeviceId(ownerId: string, deviceId: string): Promise<string[]> {
const assets = await this.repository.find({
select: { deviceAssetId: true },
where: {
ownerId,
deviceId,
isVisible: true,
},
});
return assets.map(({ deviceAssetId }) => deviceAssetId);
}
async deleteAll(ownerId: string): Promise<void> {
await this.repository.delete({ ownerId });
}