refactor(server): use UUID dto in asset controller (#2641)

* refactor: assetId => id

* chore: open api

* chore: remove unused dto

* fix(web): assetId => id

* fix: web test
This commit is contained in:
Jason Rasmussen
2023-06-01 22:19:25 -04:00
committed by GitHub
parent 422ad20641
commit a9fb1d435a
16 changed files with 184 additions and 196 deletions

View File

@@ -54,7 +54,7 @@ import FileNotEmptyValidator from '../validation/file-not-empty-validator';
import { RemoveAssetsDto } from '../album/dto/remove-assets.dto';
import { AssetBulkUploadCheckDto } from './dto/asset-check.dto';
import { AssetBulkUploadCheckResponseDto } from './response-dto/asset-check-response.dto';
import { AssetIdDto } from './dto/asset-id.dto';
import { UUIDParamDto } from '../../controllers/dto/uuid-param.dto';
import { DeviceIdDto } from './dto/device-id.dto';
import { handleDownload } from '../../app.utils';
@@ -114,14 +114,14 @@ export class AssetController {
}
@SharedLinkRoute()
@Get('/download/:assetId')
@Get('/download/:id')
@ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } })
async downloadFile(
@GetAuthUser() authUser: AuthUserDto,
@Response({ passthrough: true }) res: Res,
@Param() { assetId }: AssetIdDto,
@Param() { id }: UUIDParamDto,
) {
return this.assetService.downloadFile(authUser, assetId).then(asStreamableFile);
return this.assetService.downloadFile(authUser, id).then(asStreamableFile);
}
@SharedLinkRoute()
@@ -153,7 +153,7 @@ export class AssetController {
}
@SharedLinkRoute()
@Get('/file/:assetId')
@Get('/file/:id')
@Header('Cache-Control', 'max-age=31536000')
@ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } })
async serveFile(
@@ -161,25 +161,25 @@ export class AssetController {
@Headers() headers: Record<string, string>,
@Response({ passthrough: true }) res: Res,
@Query(new ValidationPipe({ transform: true })) query: ServeFileDto,
@Param() { assetId }: AssetIdDto,
@Param() { id }: UUIDParamDto,
) {
await this.assetService.checkAssetsAccess(authUser, [assetId]);
return this.assetService.serveFile(authUser, assetId, query, res, headers);
await this.assetService.checkAssetsAccess(authUser, [id]);
return this.assetService.serveFile(authUser, id, query, res, headers);
}
@SharedLinkRoute()
@Get('/thumbnail/:assetId')
@Get('/thumbnail/:id')
@Header('Cache-Control', 'max-age=31536000')
@ApiOkResponse({ content: { 'application/octet-stream': { schema: { type: 'string', format: 'binary' } } } })
async getAssetThumbnail(
@GetAuthUser() authUser: AuthUserDto,
@Headers() headers: Record<string, string>,
@Response({ passthrough: true }) res: Res,
@Param() { assetId }: AssetIdDto,
@Param() { id }: UUIDParamDto,
@Query(new ValidationPipe({ transform: true })) query: GetAssetThumbnailDto,
) {
await this.assetService.checkAssetsAccess(authUser, [assetId]);
return this.assetService.getAssetThumbnail(assetId, query, res, headers);
await this.assetService.checkAssetsAccess(authUser, [id]);
return this.assetService.getAssetThumbnail(id, query, res, headers);
}
@Get('/curated-objects')
@@ -259,26 +259,23 @@ export class AssetController {
* Get a single asset's information
*/
@SharedLinkRoute()
@Get('/assetById/:assetId')
async getAssetById(
@GetAuthUser() authUser: AuthUserDto,
@Param() { assetId }: AssetIdDto,
): Promise<AssetResponseDto> {
await this.assetService.checkAssetsAccess(authUser, [assetId]);
return await this.assetService.getAssetById(authUser, assetId);
@Get('/assetById/:id')
async getAssetById(@GetAuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise<AssetResponseDto> {
await this.assetService.checkAssetsAccess(authUser, [id]);
return await this.assetService.getAssetById(authUser, id);
}
/**
* Update an asset
*/
@Put('/:assetId')
@Put('/:id')
async updateAsset(
@GetAuthUser() authUser: AuthUserDto,
@Param() { assetId }: AssetIdDto,
@Param() { id }: UUIDParamDto,
@Body(ValidationPipe) dto: UpdateAssetDto,
): Promise<AssetResponseDto> {
await this.assetService.checkAssetsAccess(authUser, [assetId], true);
return await this.assetService.updateAsset(authUser, assetId, dto);
await this.assetService.checkAssetsAccess(authUser, [id], true);
return await this.assetService.updateAsset(authUser, id, dto);
}
@Delete('/')

View File

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

View File

@@ -2801,12 +2801,12 @@
]
}
},
"/asset/download/{assetId}": {
"/asset/download/{id}": {
"get": {
"operationId": "downloadFile",
"parameters": [
{
"name": "assetId",
"name": "id",
"required": true,
"in": "path",
"schema": {
@@ -2966,7 +2966,7 @@
]
}
},
"/asset/file/{assetId}": {
"/asset/file/{id}": {
"get": {
"operationId": "serveFile",
"parameters": [
@@ -2989,7 +2989,7 @@
}
},
{
"name": "assetId",
"name": "id",
"required": true,
"in": "path",
"schema": {
@@ -3035,12 +3035,12 @@
]
}
},
"/asset/thumbnail/{assetId}": {
"/asset/thumbnail/{id}": {
"get": {
"operationId": "getAssetThumbnail",
"parameters": [
{
"name": "assetId",
"name": "id",
"required": true,
"in": "path",
"schema": {
@@ -3563,13 +3563,13 @@
]
}
},
"/asset/assetById/{assetId}": {
"/asset/assetById/{id}": {
"get": {
"operationId": "getAssetById",
"description": "Get a single asset's information",
"parameters": [
{
"name": "assetId",
"name": "id",
"required": true,
"in": "path",
"schema": {
@@ -3614,13 +3614,13 @@
]
}
},
"/asset/{assetId}": {
"/asset/{id}": {
"put": {
"operationId": "updateAsset",
"description": "Update an asset",
"parameters": [
{
"name": "assetId",
"name": "id",
"required": true,
"in": "path",
"schema": {