| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Get, |
| 5 | Header, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Post, |
| 10 | Put, |
| 11 | Req, |
| 12 | Res, |
| 13 | StreamableFile, |
| 14 | } from '@nestjs/common'; |
| 15 | import { ApiExcludeController } |
| 16 | import { OptionalAuth } |
| 17 | import type { Response |
| 18 | |
| 19 | import { LFS_MEDIA_TYPE } |
| 20 | import { LfsService } |
| 21 | import { LfsBatchRequestDTO } |
| 22 | import type { GitAuthorizedRequest |
| 23 | |
| 24 | /** Git LFS's batch API and its `basic` transfer. `GitBasicAuthMiddleware` has already authorized the repository for the operation. */ |
| 25 | @Controller(':username/:repo/info/lfs/objects') |
| 26 | @ApiExcludeController() |
| 27 | @OptionalAuth() |
| 28 | export class LfsController |
| 29 | constructor(private readonly |
| 30 | |
| 31 | @Post('batch' |
| 32 | @HttpCode(HttpStatus. |
| 33 | @Header('Content-Type' |
| 34 | batch( |
| 35 | @Param('username' |
| 36 | @Body() body |
| 37 | @Req() req |
| 38 | ) { |
| 39 | return this.lfs |
| 40 | repositoryId: req.repository |
| 41 | path: `${username} |
| 42 | operation: body.operation |
| 43 | objects: body.objects |
| 44 | authorization: req.headers |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | @Put(':oid' |
| 49 | upload(@Param( |
| 50 | return this.lfs |
| 51 | repository: req.repository |
| 52 | oid, |
| 53 | contentLength: req.headers |
| 54 | body: req, |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | @Get(':oid' |
| 59 | async download( |
| 60 | @Param('oid' |
| 61 | @Req() req |
| 62 | @Res({ passthrough |
| 63 | ) { |
| 64 | const object = |
| 65 | res.set('Content-Length |
| 66 | return new StreamableFile |
| 67 | type: 'application/octet-stream', |
| 68 | }); |
| 69 | } |
| 70 | } |