-
-
Notifications
You must be signed in to change notification settings - Fork 281
Expand file tree
/
Copy pathdeleteObject.ts
More file actions
53 lines (47 loc) · 1.51 KB
/
deleteObject.ts
File metadata and controls
53 lines (47 loc) · 1.51 KB
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
49
50
51
52
53
import { FastifyInstance } from 'fastify'
import { FromSchema } from 'json-schema-to-ts'
import { createDefaultSchema, createResponse } from '../../routes-helper'
import { AuthenticatedRequest } from '../../types'
import { ROUTE_OPERATIONS } from '../operations'
const deleteObjectParamsSchema = {
type: 'object',
properties: {
bucketName: { type: 'string', examples: ['avatars'] },
'*': { type: 'string', examples: ['folder/cat.png'] },
},
required: ['bucketName', '*'],
} as const
const successResponseSchema = {
type: 'object',
properties: {
message: { type: 'string', examples: ['Successfully deleted'] },
},
}
interface deleteObjectRequestInterface extends AuthenticatedRequest {
Params: FromSchema<typeof deleteObjectParamsSchema>
}
export default async function routes(fastify: FastifyInstance) {
const summary = 'Delete an object'
const schema = createDefaultSchema(successResponseSchema, {
params: deleteObjectParamsSchema,
summary,
tags: ['object'],
})
fastify.delete<deleteObjectRequestInterface>(
'/:bucketName/*',
{
schema,
config: {
operation: { type: ROUTE_OPERATIONS.DELETE_OBJECT },
},
},
async (request, response) => {
const { bucketName } = request.params
const objectName = request.params['*']
await request.storage
.from(bucketName)
.deleteObject({ objectName, signal: request.signals.disconnect.signal })
return response.status(200).send(createResponse('Successfully deleted'))
}
)
}