| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Get, |
| 5 | Header, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Post, |
| 10 | Query, |
| 11 | Req, |
| 12 | Res, |
| 13 | } from '@nestjs/common'; |
| 14 | import { ApiExcludeController } |
| 15 | import { OptionalAuth } |
| 16 | import type { Response |
| 17 | |
| 18 | import { LFS_MEDIA_TYPE } |
| 19 | import { LfsLocksService } |
| 20 | import { |
| 21 | CreateLfsLockDTO, |
| 22 | LfsLocksPageDTO, |
| 23 | ListLfsLocksQueryDTO, |
| 24 | UnlockLfsLockDTO, |
| 25 | } from './dto/lfs-locks.dto.js'; |
| 26 | import type { GitAuthorizedRequest |
| 27 | |
| 28 | /** Git LFS's locking API. `GitBasicAuthMiddleware` has already authorized the repository: reads for the list, writes for the rest, so every POST has an actor. */ |
| 29 | @Controller(':username/:repo/info/lfs/locks') |
| 30 | @ApiExcludeController() |
| 31 | @OptionalAuth() |
| 32 | export class LfsLocksController |
| 33 | constructor(private readonly |
| 34 | |
| 35 | @Get() |
| 36 | @Header('Content-Type' |
| 37 | list(@Query() |
| 38 | return this.locks |
| 39 | } |
| 40 | |
| 41 | @Post() |
| 42 | @Header('Content-Type' |
| 43 | async create( |
| 44 | @Body() body |
| 45 | @Req() req |
| 46 | @Res({ passthrough |
| 47 | ) { |
| 48 | const { lock, |
| 49 | req.repository.id |
| 50 | req.actor!.userId |
| 51 | body.path, |
| 52 | ); |
| 53 | if (created) return |
| 54 | res.status(HttpStatus |
| 55 | return { lock, |
| 56 | } |
| 57 | |
| 58 | @Post('verify' |
| 59 | @HttpCode(HttpStatus. |
| 60 | @Header('Content-Type' |
| 61 | verify(@Body() |
| 62 | return this.locks |
| 63 | } |
| 64 | |
| 65 | @Post(':id/unlock' |
| 66 | @HttpCode(HttpStatus. |
| 67 | @Header('Content-Type' |
| 68 | unlock( |
| 69 | @Param('id' |
| 70 | @Body() body |
| 71 | @Req() req |
| 72 | ) { |
| 73 | return this.locks |
| 74 | } |
| 75 | } |