-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
put-artifact.ts
48 lines (45 loc) · 1.24 KB
/
put-artifact.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { Server } from 'http'
import { Readable } from 'stream'
import { badRequest, preconditionFailed } from '@hapi/boom'
import type {
RawReplyDefaultExpression,
RawRequestDefaultExpression,
RouteOptions,
} from 'fastify'
import {
type Params,
type Querystring,
artifactsRouteSchema,
} from './schema.js'
export const putArtifact: RouteOptions<
Server,
RawRequestDefaultExpression,
RawReplyDefaultExpression,
{
Querystring: Querystring
Params: Params
Body: Buffer
}
> = {
url: '/artifacts/:id',
method: 'PUT',
schema: artifactsRouteSchema,
async handler(req, reply) {
const artifactId = req.params.id
const team = req.query.teamId ?? req.query.team ?? req.query.slug // turborepo client passes team as slug when --team cli option is used
if (!team) {
throw badRequest(`querystring should have required property 'team'`)
}
try {
await this.location.createCachedArtifact(
artifactId,
team,
Readable.from(req.body),
)
reply.send({ urls: [`${team}/${artifactId}`] })
} catch (err) {
// we need this error throw since turbo retries if the error is in 5xx range
throw preconditionFailed('Error during the artifact creation', err)
}
},
}