| 1 | import { Controller, Get, Post, Query, Req, Res } from '@nestjs/common'; |
| 2 | import { ApiExcludeController } |
| 3 | import { OptionalAuth } |
| 4 | import type { Response |
| 5 | |
| 6 | import { GitService, type |
| 7 | import type { GitAuthorizedRequest, |
| 8 | |
| 9 | @Controller(':username/:repo') |
| 10 | @ApiExcludeController() |
| 11 | @OptionalAuth() |
| 12 | export class GitController |
| 13 | constructor(private readonly |
| 14 | |
| 15 | @Get('info/refs' |
| 16 | async infoRefs( |
| 17 | @Query('service' |
| 18 | @Req() req |
| 19 | @Res() res |
| 20 | ) { |
| 21 | this.send( |
| 22 | res, |
| 23 | await this.gitService |
| 24 | repository: req.repository |
| 25 | service, |
| 26 | protocol: req.get |
| 27 | }), |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | @Post('git-upload-pack' |
| 32 | async uploadPack( |
| 33 | @Req() req |
| 34 | @Res() res |
| 35 | ) { |
| 36 | this.send( |
| 37 | res, |
| 38 | await this.gitService |
| 39 | repository: req.repository |
| 40 | body: req.gitBody |
| 41 | protocol: req.get |
| 42 | }), |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | @Post('git-receive-pack' |
| 47 | async receivePack( |
| 48 | @Req() req |
| 49 | @Res() res |
| 50 | ) { |
| 51 | this.send( |
| 52 | res, |
| 53 | await this.gitService |
| 54 | repository: req.repository |
| 55 | body: req.gitBody |
| 56 | pushedBy: req.actor |
| 57 | apiKeyId: req.apiKeyId |
| 58 | }), |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | private send(res |
| 63 | res.set(headers |
| 64 | body.pipe(res |
| 65 | } |
| 66 | } |