| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | Headers, |
| 7 | HttpCode, |
| 8 | HttpStatus, |
| 9 | Param, |
| 10 | ParseIntPipe, |
| 11 | Patch, |
| 12 | Post, |
| 13 | Query, |
| 14 | Res, |
| 15 | StreamableFile, |
| 16 | UseFilters, |
| 17 | UseInterceptors, |
| 18 | } from '@nestjs/common'; |
| 19 | import { ApiOperation, ApiTags |
| 20 | import { AllowAnonymous } |
| 21 | import type { Response |
| 22 | |
| 23 | import type { GithubViewer |
| 24 | import { Viewer } |
| 25 | import { GithubRestFilter } |
| 26 | import { GithubRestInterceptor } |
| 27 | import { GithubPageQueryDTO } |
| 28 | import { |
| 29 | GithubCreateReleaseDTO, |
| 30 | GithubUpdateReleaseAssetDTO, |
| 31 | GithubUpdateReleaseDTO, |
| 32 | } from './dto/release.dto.js'; |
| 33 | import { GithubReleasesService } |
| 34 | |
| 35 | const ID = new |
| 36 | |
| 37 | @Controller('v3/repos/:owner/:repo/releases') |
| 38 | @ApiTags('GitHub compatibility') |
| 39 | @AllowAnonymous() |
| 40 | @UseFilters(GithubRestFilter) |
| 41 | @UseInterceptors(GithubRestInterceptor) |
| 42 | export class GithubReleasesController |
| 43 | constructor(private readonly |
| 44 | |
| 45 | @Get() |
| 46 | @ApiOperation({ summary |
| 47 | list( |
| 48 | @Param('owner' |
| 49 | @Param('repo' |
| 50 | @Query() query |
| 51 | @Viewer() viewer |
| 52 | ) { |
| 53 | return this.releases |
| 54 | } |
| 55 | |
| 56 | @Post() |
| 57 | @ApiOperation({ |
| 58 | summary: 'Create a release, and its tag when the tag does not exist', |
| 59 | }) |
| 60 | create( |
| 61 | @Param('owner' |
| 62 | @Param('repo' |
| 63 | @Body() body |
| 64 | @Viewer() viewer |
| 65 | ) { |
| 66 | return this.releases |
| 67 | } |
| 68 | |
| 69 | @Get('latest' |
| 70 | @ApiOperation({ |
| 71 | summary: 'The newest published release that is not a prerelease', |
| 72 | }) |
| 73 | latest( |
| 74 | @Param('owner' |
| 75 | @Param('repo' |
| 76 | @Viewer() viewer |
| 77 | ) { |
| 78 | return this.releases |
| 79 | } |
| 80 | |
| 81 | @Get('tags/*tag' |
| 82 | @ApiOperation({ summary |
| 83 | byTag( |
| 84 | @Param('owner' |
| 85 | @Param('repo' |
| 86 | @Param('tag' |
| 87 | @Viewer() viewer |
| 88 | ) { |
| 89 | return this.releases |
| 90 | } |
| 91 | |
| 92 | @Get('assets/:asset_id' |
| 93 | @ApiOperation({ |
| 94 | summary: |
| 95 | 'A release asset, or its bytes when asked for application/octet-stream', |
| 96 | }) |
| 97 | async asset( |
| 98 | @Param('owner' |
| 99 | @Param('repo' |
| 100 | @Param('asset_id' |
| 101 | @Headers('accept' |
| 102 | @Viewer() viewer |
| 103 | @Res({ passthrough |
| 104 | ) { |
| 105 | if (!/application\/ |
| 106 | return this.releases |
| 107 | const download = |
| 108 | { owner, repo |
| 109 | assetId, |
| 110 | ); |
| 111 | // GitHub may redirect or stream; clients handle both, and streaming keeps the bytes behind this API's own checks. |
| 112 | response.set({ |
| 113 | 'Content-Type': 'application/octet-stream', |
| 114 | 'Content-Length': String( |
| 115 | 'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent |
| 116 | 'X-Content-Type-Options': 'nosniff', |
| 117 | }); |
| 118 | return new StreamableFile |
| 119 | } |
| 120 | |
| 121 | @Patch('assets/:asset_id' |
| 122 | @ApiOperation({ summary |
| 123 | updateAsset( |
| 124 | @Param('owner' |
| 125 | @Param('repo' |
| 126 | @Param('asset_id' |
| 127 | @Body() body |
| 128 | @Viewer() viewer |
| 129 | ) { |
| 130 | return this.releases |
| 131 | } |
| 132 | |
| 133 | @Delete('assets/:asset_id' |
| 134 | @HttpCode(HttpStatus. |
| 135 | @ApiOperation({ summary |
| 136 | deleteAsset( |
| 137 | @Param('owner' |
| 138 | @Param('repo' |
| 139 | @Param('asset_id' |
| 140 | @Viewer() viewer |
| 141 | ) { |
| 142 | return this.releases |
| 143 | } |
| 144 | |
| 145 | @Get(':release_id' |
| 146 | @ApiOperation({ |
| 147 | summary: 'A release by its integer id, drafts included for writers', |
| 148 | }) |
| 149 | get( |
| 150 | @Param('owner' |
| 151 | @Param('repo' |
| 152 | @Param('release_id' |
| 153 | @Viewer() viewer |
| 154 | ) { |
| 155 | return this.releases |
| 156 | } |
| 157 | |
| 158 | @Patch(':release_id' |
| 159 | @ApiOperation({ summary |
| 160 | update( |
| 161 | @Param('owner' |
| 162 | @Param('repo' |
| 163 | @Param('release_id' |
| 164 | @Body() body |
| 165 | @Viewer() viewer |
| 166 | ) { |
| 167 | return this.releases |
| 168 | } |
| 169 | |
| 170 | @Delete(':release_id' |
| 171 | @HttpCode(HttpStatus. |
| 172 | @ApiOperation({ summary |
| 173 | delete( |
| 174 | @Param('owner' |
| 175 | @Param('repo' |
| 176 | @Param('release_id' |
| 177 | @Viewer() viewer |
| 178 | ) { |
| 179 | return this.releases |
| 180 | } |
| 181 | |
| 182 | @Get(':release_id/assets' |
| 183 | @ApiOperation({ summary |
| 184 | listAssets( |
| 185 | @Param('owner' |
| 186 | @Param('repo' |
| 187 | @Param('release_id' |
| 188 | @Query() query |
| 189 | @Viewer() viewer |
| 190 | ) { |
| 191 | return this.releases |
| 192 | } |
| 193 | } |