2023-06-30 12:24:28 -04:00
|
|
|
import {
|
2023-10-06 07:01:14 +00:00
|
|
|
AssetBulkDeleteDto,
|
2023-08-16 16:04:55 -04:00
|
|
|
AssetBulkUpdateDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
AssetIdsDto,
|
2023-08-18 10:31:48 -04:00
|
|
|
AssetJobsDto,
|
2023-08-04 17:07:15 -04:00
|
|
|
AssetResponseDto,
|
2023-11-14 17:47:15 -05:00
|
|
|
AssetSearchDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
AssetService,
|
2023-07-14 09:30:17 -04:00
|
|
|
AssetStatsDto,
|
|
|
|
|
AssetStatsResponseDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
AuthUserDto,
|
2023-10-06 07:01:14 +00:00
|
|
|
BulkIdsDto,
|
2023-08-15 11:49:32 -04:00
|
|
|
DownloadInfoDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
DownloadResponseDto,
|
2023-08-24 21:28:50 +02:00
|
|
|
MapMarkerDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
MapMarkerResponseDto,
|
|
|
|
|
MemoryLaneDto,
|
2023-08-24 21:28:50 +02:00
|
|
|
MemoryLaneResponseDto,
|
2023-09-23 17:28:55 +02:00
|
|
|
RandomAssetsDto,
|
2023-08-04 17:07:15 -04:00
|
|
|
TimeBucketAssetDto,
|
|
|
|
|
TimeBucketDto,
|
|
|
|
|
TimeBucketResponseDto,
|
2023-10-06 07:01:14 +00:00
|
|
|
TrashAction,
|
2023-09-04 22:25:31 -04:00
|
|
|
UpdateAssetDto as UpdateDto,
|
2023-10-22 02:38:07 +00:00
|
|
|
UpdateStackParentDto,
|
2023-06-30 12:24:28 -04:00
|
|
|
} from '@app/domain';
|
2023-10-06 07:01:14 +00:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Delete,
|
|
|
|
|
Get,
|
|
|
|
|
HttpCode,
|
|
|
|
|
HttpStatus,
|
|
|
|
|
Param,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Query,
|
|
|
|
|
StreamableFile,
|
|
|
|
|
} from '@nestjs/common';
|
2023-06-30 12:24:28 -04:00
|
|
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
2023-11-25 15:46:20 +00:00
|
|
|
import { DeviceIdDto } from '../api-v1/asset/dto/device-id.dto';
|
2023-09-04 15:45:59 -04:00
|
|
|
import { AuthUser, Authenticated, SharedLinkRoute } from '../app.guard';
|
|
|
|
|
import { UseValidation, asStreamableFile } from '../app.utils';
|
2023-11-03 21:33:15 -04:00
|
|
|
import { Route } from '../interceptors';
|
2023-06-30 12:24:28 -04:00
|
|
|
import { UUIDParamDto } from './dto/uuid-param.dto';
|
2023-05-21 08:26:06 +02:00
|
|
|
|
2023-11-14 17:47:15 -05:00
|
|
|
@ApiTags('Asset')
|
|
|
|
|
@Controller('assets')
|
|
|
|
|
@Authenticated()
|
|
|
|
|
@UseValidation()
|
|
|
|
|
export class AssetsController {
|
|
|
|
|
constructor(private service: AssetService) {}
|
|
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
|
searchAssets(@AuthUser() authUser: AuthUserDto, @Query() dto: AssetSearchDto): Promise<AssetResponseDto[]> {
|
|
|
|
|
return this.service.search(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-21 08:26:06 +02:00
|
|
|
@ApiTags('Asset')
|
2023-11-03 21:33:15 -04:00
|
|
|
@Controller(Route.ASSET)
|
2023-05-21 08:26:06 +02:00
|
|
|
@Authenticated()
|
|
|
|
|
@UseValidation()
|
|
|
|
|
export class AssetController {
|
|
|
|
|
constructor(private service: AssetService) {}
|
|
|
|
|
|
2023-06-16 15:36:07 -04:00
|
|
|
@Get('map-marker')
|
2023-06-16 15:39:53 -04:00
|
|
|
getMapMarkers(@AuthUser() authUser: AuthUserDto, @Query() options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
|
2023-05-21 08:26:06 +02:00
|
|
|
return this.service.getMapMarkers(authUser, options);
|
|
|
|
|
}
|
2023-06-14 20:47:18 -05:00
|
|
|
|
|
|
|
|
@Get('memory-lane')
|
2023-06-16 15:39:53 -04:00
|
|
|
getMemoryLane(@AuthUser() authUser: AuthUserDto, @Query() dto: MemoryLaneDto): Promise<MemoryLaneResponseDto[]> {
|
2023-06-15 14:05:30 -04:00
|
|
|
return this.service.getMemoryLane(authUser, dto);
|
2023-06-14 20:47:18 -05:00
|
|
|
}
|
2023-06-30 12:24:28 -04:00
|
|
|
|
2023-09-23 17:28:55 +02:00
|
|
|
@Get('random')
|
|
|
|
|
getRandom(@AuthUser() authUser: AuthUserDto, @Query() dto: RandomAssetsDto): Promise<AssetResponseDto[]> {
|
|
|
|
|
return this.service.getRandom(authUser, dto.count ?? 1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-30 12:24:28 -04:00
|
|
|
@SharedLinkRoute()
|
2023-08-15 11:49:32 -04:00
|
|
|
@Post('download/info')
|
|
|
|
|
getDownloadInfo(@AuthUser() authUser: AuthUserDto, @Body() dto: DownloadInfoDto): Promise<DownloadResponseDto> {
|
2023-06-30 12:24:28 -04:00
|
|
|
return this.service.getDownloadInfo(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SharedLinkRoute()
|
2023-08-15 11:49:32 -04:00
|
|
|
@Post('download/archive')
|
2023-06-30 12:24:28 -04:00
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } })
|
|
|
|
|
downloadArchive(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetIdsDto): Promise<StreamableFile> {
|
|
|
|
|
return this.service.downloadArchive(authUser, dto).then(asStreamableFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SharedLinkRoute()
|
|
|
|
|
@Post('download/:id')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
@ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } })
|
|
|
|
|
downloadFile(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto) {
|
|
|
|
|
return this.service.downloadFile(authUser, id).then(asStreamableFile);
|
|
|
|
|
}
|
2023-07-14 09:30:17 -04:00
|
|
|
|
2023-11-25 15:46:20 +00:00
|
|
|
/**
|
|
|
|
|
* Get all asset of a device that are in the database, ID only.
|
|
|
|
|
*/
|
|
|
|
|
@Get('/device/:deviceId')
|
|
|
|
|
getAllUserAssetsByDeviceId(@AuthUser() authUser: AuthUserDto, @Param() { deviceId }: DeviceIdDto) {
|
|
|
|
|
return this.service.getUserAssetsByDeviceId(authUser, deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 09:30:17 -04:00
|
|
|
@Get('statistics')
|
2023-11-03 21:33:15 -04:00
|
|
|
getAssetStatistics(@AuthUser() authUser: AuthUserDto, @Query() dto: AssetStatsDto): Promise<AssetStatsResponseDto> {
|
2023-07-14 09:30:17 -04:00
|
|
|
return this.service.getStatistics(authUser, dto);
|
|
|
|
|
}
|
2023-08-04 17:07:15 -04:00
|
|
|
|
|
|
|
|
@Authenticated({ isShared: true })
|
|
|
|
|
@Get('time-buckets')
|
|
|
|
|
getTimeBuckets(@AuthUser() authUser: AuthUserDto, @Query() dto: TimeBucketDto): Promise<TimeBucketResponseDto[]> {
|
|
|
|
|
return this.service.getTimeBuckets(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Authenticated({ isShared: true })
|
|
|
|
|
@Get('time-bucket')
|
2023-11-03 21:33:15 -04:00
|
|
|
getTimeBucket(@AuthUser() authUser: AuthUserDto, @Query() dto: TimeBucketAssetDto): Promise<AssetResponseDto[]> {
|
|
|
|
|
return this.service.getTimeBucket(authUser, dto) as Promise<AssetResponseDto[]>;
|
2023-08-04 17:07:15 -04:00
|
|
|
}
|
2023-08-16 16:04:55 -04:00
|
|
|
|
2023-08-18 10:31:48 -04:00
|
|
|
@Post('jobs')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
runAssetJobs(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetJobsDto): Promise<void> {
|
|
|
|
|
return this.service.run(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 16:04:55 -04:00
|
|
|
@Put()
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
updateAssets(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetBulkUpdateDto): Promise<void> {
|
|
|
|
|
return this.service.updateAll(authUser, dto);
|
|
|
|
|
}
|
2023-09-04 22:25:31 -04:00
|
|
|
|
2023-10-06 07:01:14 +00:00
|
|
|
@Delete()
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
deleteAssets(@AuthUser() authUser: AuthUserDto, @Body() dto: AssetBulkDeleteDto): Promise<void> {
|
|
|
|
|
return this.service.deleteAll(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('restore')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
restoreAssets(@AuthUser() authUser: AuthUserDto, @Body() dto: BulkIdsDto): Promise<void> {
|
|
|
|
|
return this.service.restoreAll(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('trash/empty')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
emptyTrash(@AuthUser() authUser: AuthUserDto): Promise<void> {
|
|
|
|
|
return this.service.handleTrashAction(authUser, TrashAction.EMPTY_ALL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('trash/restore')
|
|
|
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
|
|
|
restoreTrash(@AuthUser() authUser: AuthUserDto): Promise<void> {
|
|
|
|
|
return this.service.handleTrashAction(authUser, TrashAction.RESTORE_ALL);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 02:38:07 +00:00
|
|
|
@Put('stack/parent')
|
|
|
|
|
@HttpCode(HttpStatus.OK)
|
|
|
|
|
updateStackParent(@AuthUser() authUser: AuthUserDto, @Body() dto: UpdateStackParentDto): Promise<void> {
|
|
|
|
|
return this.service.updateStackParent(authUser, dto);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 22:25:31 -04:00
|
|
|
@Put(':id')
|
|
|
|
|
updateAsset(
|
|
|
|
|
@AuthUser() authUser: AuthUserDto,
|
|
|
|
|
@Param() { id }: UUIDParamDto,
|
|
|
|
|
@Body() dto: UpdateDto,
|
|
|
|
|
): Promise<AssetResponseDto> {
|
|
|
|
|
return this.service.update(authUser, id, dto);
|
|
|
|
|
}
|
2023-05-21 08:26:06 +02:00
|
|
|
}
|