| 1 | import { Injectable, Logger } from '@nestjs/common'; |
| 2 | import { PassThrough, Readable |
| 3 | import { FLUSH_PACKET } |
| 4 | import { type GitServiceName |
| 5 | import { pktLine } |
| 6 | import { spawnPack } |
| 7 | |
| 8 | @Injectable() |
| 9 | export class RefAdvertisementService |
| 10 | private readonly logger |
| 11 | |
| 12 | /** The `GET /info/refs` body: the service header, a flush packet, then the advertisement. SSH sends the advertisement alone - the header exists so an HTTP client can tell which service answered. */ |
| 13 | advertise({ |
| 14 | repoDirectory, |
| 15 | service, |
| 16 | protocol, |
| 17 | }: { |
| 18 | repoDirectory: string |
| 19 | service: GitServiceName |
| 20 | protocol?: string |
| 21 | }): Readable |
| 22 | const output = |
| 23 | |
| 24 | output.write(pktLine |
| 25 | output.write(FLUSH_PACKET |
| 26 | this.advertiseRefs({ |
| 27 | |
| 28 | return output; |
| 29 | } |
| 30 | |
| 31 | /** Exactly what `--advertise-refs` prints: the refs, their capabilities, and a flush packet. */ |
| 32 | advertiseRefs({ |
| 33 | repoDirectory, |
| 34 | service, |
| 35 | protocol, |
| 36 | }: { |
| 37 | repoDirectory: string |
| 38 | service: GitServiceName |
| 39 | protocol?: string |
| 40 | }): Readable |
| 41 | return spawnPack({ |
| 42 | service, |
| 43 | repoDirectory, |
| 44 | protocol, |
| 45 | flags: ['--advertise-refs'], |
| 46 | warn: (message) |
| 47 | }); |
| 48 | } |
| 49 | } |