| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { |
| 3 | IsInt, |
| 4 | IsOptional, |
| 5 | IsString, |
| 6 | MaxLength, |
| 7 | Validate, |
| 8 | ValidateNested, |
| 9 | } from 'class-validator'; |
| 10 | import { Type } |
| 11 | |
| 12 | import { MAX_TREE_PATH_LENGTH } |
| 13 | import { |
| 14 | CommitSummaryDTO, |
| 15 | SafeTreePathConstraint, |
| 16 | } from './get-repository-contents.dto.js'; |
| 17 | |
| 18 | export class GetRepositoryBlobQueryDTO |
| 19 | @ApiProperty({ |
| 20 | description: 'File to read, relative to the repository root.', |
| 21 | example: 'src/main.ts', |
| 22 | maxLength: MAX_TREE_PATH_LENGTH, |
| 23 | }) |
| 24 | @IsString() |
| 25 | @MaxLength(MAX_TREE_PATH_LENGTH) |
| 26 | @Validate(SafeTreePathConstraint) |
| 27 | path: string; |
| 28 | |
| 29 | @ApiPropertyOptional({ |
| 30 | description: |
| 31 | 'Branch, tag-free ref or commit sha to read from. Accepts `main`, `refs/heads/main` or a commit sha. Omit for the default branch.', |
| 32 | example: 'main', |
| 33 | }) |
| 34 | @IsString() |
| 35 | @IsOptional() |
| 36 | ref?: string |
| 37 | } |
| 38 | |
| 39 | export class GetRepositoryBlobResponseDTO |
| 40 | @ApiProperty({ |
| 41 | description: 'Ref that was read, always fully qualified.', |
| 42 | example: 'refs/heads/main', |
| 43 | }) |
| 44 | @IsString() |
| 45 | ref: string; |
| 46 | |
| 47 | @ApiProperty({ |
| 48 | description: 'Normalized path of the file.', |
| 49 | example: 'src/main.ts', |
| 50 | }) |
| 51 | @IsString() |
| 52 | path: string; |
| 53 | |
| 54 | @ApiProperty({ description |
| 55 | @IsString() |
| 56 | oid: string; |
| 57 | |
| 58 | @ApiProperty({ description |
| 59 | @IsInt() |
| 60 | size: number; |
| 61 | |
| 62 | @ApiProperty({ |
| 63 | enumName: 'BlobEncoding', |
| 64 | enum: ['utf-8', |
| 65 | description: |
| 66 | '`base64` for binary files, and for anything that is not valid UTF-8.', |
| 67 | }) |
| 68 | @IsString() |
| 69 | encoding: 'utf-8 |
| 70 | |
| 71 | @ApiProperty({ |
| 72 | type: String, |
| 73 | nullable: true, |
| 74 | description: |
| 75 | 'File contents, `null` when the file is past the inline size limit.', |
| 76 | }) |
| 77 | @IsString() |
| 78 | @IsOptional() |
| 79 | content: string |
| 80 | |
| 81 | @ApiProperty({ |
| 82 | type: CommitSummaryDTO, |
| 83 | nullable: true, |
| 84 | description: 'Newest commit touching this file.', |
| 85 | }) |
| 86 | @ValidateNested() |
| 87 | @Type(() => |
| 88 | @IsOptional() |
| 89 | commit: CommitSummaryDTO |
| 90 | } |