|
| 1 | +import { |
| 2 | + IsString, |
| 3 | + IsOptional, |
| 4 | + IsArray, |
| 5 | + IsEnum, |
| 6 | + IsNumber, |
| 7 | + IsBoolean, |
| 8 | + IsObject, |
| 9 | + IsInt, |
| 10 | + Min, |
| 11 | + Max, |
| 12 | + MaxLength, |
| 13 | + MinLength, |
| 14 | +} from "class-validator"; |
| 15 | +import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"; |
| 16 | +import { |
| 17 | + FileStorageBackend, |
| 18 | + FileCategory, |
| 19 | +} from "../entities/uploaded-file.entity"; |
| 20 | + |
| 21 | +export class UploadFileDto { |
| 22 | + @ApiPropertyOptional({ |
| 23 | + example: "profile-photo.jpg", |
| 24 | + description: "Original file name", |
| 25 | + }) |
| 26 | + @IsOptional() |
| 27 | + @IsString() |
| 28 | + @MaxLength(255) |
| 29 | + originalName?: string; |
| 30 | + |
| 31 | + @ApiPropertyOptional({ |
| 32 | + enum: FileStorageBackend, |
| 33 | + default: FileStorageBackend.LOCAL, |
| 34 | + description: "Storage backend to use", |
| 35 | + }) |
| 36 | + @IsOptional() |
| 37 | + @IsEnum(FileStorageBackend) |
| 38 | + storageBackend?: FileStorageBackend; |
| 39 | + |
| 40 | + @ApiPropertyOptional({ |
| 41 | + example: ["profile", "avatar"], |
| 42 | + description: "Tags to associate with the file", |
| 43 | + }) |
| 44 | + @IsOptional() |
| 45 | + @IsArray() |
| 46 | + @IsString({ each: true }) |
| 47 | + tags?: string[]; |
| 48 | + |
| 49 | + @ApiPropertyOptional({ example: "User profile photo" }) |
| 50 | + @IsOptional() |
| 51 | + @IsString() |
| 52 | + @MaxLength(512) |
| 53 | + description?: string; |
| 54 | + |
| 55 | + @ApiPropertyOptional({ |
| 56 | + description: "Make file publicly accessible", |
| 57 | + default: false, |
| 58 | + }) |
| 59 | + @IsOptional() |
| 60 | + @IsBoolean() |
| 61 | + isPublic?: boolean; |
| 62 | + |
| 63 | + @ApiPropertyOptional({ |
| 64 | + description: "Expiry time in seconds from now", |
| 65 | + example: 3600, |
| 66 | + }) |
| 67 | + @IsOptional() |
| 68 | + @IsNumber() |
| 69 | + @Min(60) |
| 70 | + @Max(31536000) |
| 71 | + expiresIn?: number; |
| 72 | +} |
| 73 | + |
| 74 | +export class UpdateFileMetadataDto { |
| 75 | + @ApiPropertyOptional({ |
| 76 | + example: ["profile", "updated"], |
| 77 | + description: "Tags to associate with the file", |
| 78 | + }) |
| 79 | + @IsOptional() |
| 80 | + @IsArray() |
| 81 | + @IsString({ each: true }) |
| 82 | + tags?: string[]; |
| 83 | + |
| 84 | + @ApiPropertyOptional({ example: "Updated description" }) |
| 85 | + @IsOptional() |
| 86 | + @IsString() |
| 87 | + @MaxLength(512) |
| 88 | + description?: string; |
| 89 | + |
| 90 | + @ApiPropertyOptional({ example: { key: "value" } }) |
| 91 | + @IsOptional() |
| 92 | + @IsObject() |
| 93 | + metadata?: Record<string, any>; |
| 94 | +} |
| 95 | + |
| 96 | +export class GenerateThumbnailDto { |
| 97 | + @ApiProperty({ example: 200, description: "Thumbnail width in pixels" }) |
| 98 | + @IsInt() |
| 99 | + @Min(16) |
| 100 | + @Max(2048) |
| 101 | + width: number; |
| 102 | + |
| 103 | + @ApiProperty({ example: 200, description: "Thumbnail height in pixels" }) |
| 104 | + @IsInt() |
| 105 | + @Min(16) |
| 106 | + @Max(2048) |
| 107 | + height: number; |
| 108 | + |
| 109 | + @ApiPropertyOptional({ |
| 110 | + example: "webp", |
| 111 | + default: "webp", |
| 112 | + description: "Output format", |
| 113 | + }) |
| 114 | + @IsOptional() |
| 115 | + @IsString() |
| 116 | + format?: string; |
| 117 | + |
| 118 | + @ApiPropertyOptional({ |
| 119 | + example: "thumb-large", |
| 120 | + description: "Variant name for the thumbnail", |
| 121 | + }) |
| 122 | + @IsOptional() |
| 123 | + @IsString() |
| 124 | + @MaxLength(64) |
| 125 | + variant?: string; |
| 126 | +} |
| 127 | + |
| 128 | +export class GetDownloadUrlDto { |
| 129 | + @ApiPropertyOptional({ |
| 130 | + example: 3600, |
| 131 | + default: 3600, |
| 132 | + description: "URL expiry in seconds", |
| 133 | + }) |
| 134 | + @IsOptional() |
| 135 | + @IsNumber() |
| 136 | + @Min(60) |
| 137 | + @Max(86400) |
| 138 | + expiresIn?: number; |
| 139 | +} |
| 140 | + |
| 141 | +export class FileSearchDto { |
| 142 | + @ApiPropertyOptional({ example: "profile" }) |
| 143 | + @IsOptional() |
| 144 | + @IsString() |
| 145 | + name?: string; |
| 146 | + |
| 147 | + @ApiPropertyOptional({ enum: FileCategory }) |
| 148 | + @IsOptional() |
| 149 | + @IsEnum(FileCategory) |
| 150 | + category?: FileCategory; |
| 151 | + |
| 152 | + @ApiPropertyOptional({ example: ["profile", "avatar"] }) |
| 153 | + @IsOptional() |
| 154 | + @IsArray() |
| 155 | + @IsString({ each: true }) |
| 156 | + tags?: string[]; |
| 157 | + |
| 158 | + @ApiPropertyOptional({ example: 1024000, description: "Max size in bytes" }) |
| 159 | + @IsOptional() |
| 160 | + @IsNumber() |
| 161 | + @Min(0) |
| 162 | + maxSize?: number; |
| 163 | + |
| 164 | + @ApiPropertyOptional({ example: 1024, description: "Min size in bytes" }) |
| 165 | + @IsOptional() |
| 166 | + @IsNumber() |
| 167 | + @Min(0) |
| 168 | + minSize?: number; |
| 169 | + |
| 170 | + @ApiPropertyOptional({ example: 20, default: 20 }) |
| 171 | + @IsOptional() |
| 172 | + @IsInt() |
| 173 | + @Min(1) |
| 174 | + @Max(100) |
| 175 | + limit?: number; |
| 176 | + |
| 177 | + @ApiPropertyOptional({ example: 0, default: 0 }) |
| 178 | + @IsOptional() |
| 179 | + @IsInt() |
| 180 | + @Min(0) |
| 181 | + offset?: number; |
| 182 | +} |
| 183 | + |
| 184 | +export class FileCleanupDto { |
| 185 | + @ApiPropertyOptional({ |
| 186 | + example: 86400, |
| 187 | + description: "Delete files older than this many seconds", |
| 188 | + default: 86400, |
| 189 | + }) |
| 190 | + @IsOptional() |
| 191 | + @IsNumber() |
| 192 | + @Min(60) |
| 193 | + olderThanSeconds?: number; |
| 194 | + |
| 195 | + @ApiPropertyOptional({ |
| 196 | + description: "Only clean up files for this user", |
| 197 | + }) |
| 198 | + @IsOptional() |
| 199 | + @IsString() |
| 200 | + userId?: string; |
| 201 | + |
| 202 | + @ApiPropertyOptional({ |
| 203 | + description: "Dry run - return what would be deleted without deleting", |
| 204 | + default: false, |
| 205 | + }) |
| 206 | + @IsOptional() |
| 207 | + @IsBoolean() |
| 208 | + dryRun?: boolean; |
| 209 | +} |
0 commit comments