| 1 | import { Controller, Get, Query } from '@nestjs/common' |
| 2 | import { ApiTags } from '@nestjs/swagger' |
| 3 | import { GetToken, TokenInfo } from '@yikart/aitoearn-auth' |
| 4 | import { AssetListVo } from '@yikart/assets' |
| 5 | import { ApiDoc, createZodDto, PaginationDtoSchema, UserType } from '@yikart/common' |
| 6 | import { AssetRepository, AssetStatus, AssetType } from '@yikart/mongodb' |
| 7 | |
| 8 | const assetListQuerySchema = PaginationDtoSchema |
| 9 | class AssetListQueryDto extends createZodDto(assetListQuerySchema) {} |
| 10 | |
| 11 | @ApiTags('Me/Ai/Assets') |
| 12 | @Controller('ai/assets') |
| 13 | export class AssetsController { |
| 14 | constructor(private readonly assetRepo: AssetRepository) {} |
| 15 | |
| 16 | @ApiDoc({ |
| 17 | summary: 'Get User AI Generated Assets', |
| 18 | query: AssetListQueryDto.schema, |
| 19 | response: AssetListVo, |
| 20 | }) |
| 21 | @Get('/') |
| 22 | async listAssetsWithPagination( |
| 23 | @GetToken() token: TokenInfo, |
| 24 | @Query() query: AssetListQueryDto, |
| 25 | ): Promise<AssetListVo> { |
| 26 | const { list, total } = await this.assetRepo.listWithPagination({ |
| 27 | userId: token.id, |
| 28 | userType: UserType.User, |
| 29 | types: [ |
| 30 | AssetType.AiImage, |
| 31 | AssetType.AiVideo, |
| 32 | AssetType.AiCard, |
| 33 | AssetType.AiChatImage, |
| 34 | AssetType.AideoOutput, |
| 35 | AssetType.VideoEdit, |
| 36 | AssetType.DramaRecap, |
| 37 | AssetType.StyleTransfer, |
| 38 | AssetType.ImageEdit, |
| 39 | ], |
| 40 | statuses: [AssetStatus.Confirmed, AssetStatus.Uploaded], |
| 41 | ...query, |
| 42 | }) |
| 43 | return new AssetListVo(list.map(item => ({ ...item, url: item.path })), total, query) |
| 44 | } |
| 45 | } |
| 46 |