@@ -3,7 +3,8 @@ import { FromSchema } from 'json-schema-to-ts'
3
3
import { createDefaultSchema } from '../../generic-routes'
4
4
import { AuthenticatedRequest } from '../../request'
5
5
import { ImageRenderer } from '../../../storage/renderer'
6
- import { transformationQueryString } from '../../schemas/transformations'
6
+ import { getConfig } from '../../../config'
7
+ import { transformationOptionsSchema } from '../../schemas/transformations'
7
8
8
9
const getSignedURLParamsSchema = {
9
10
type : 'object' ,
@@ -17,15 +18,14 @@ const getSignedURLBodySchema = {
17
18
type : 'object' ,
18
19
properties : {
19
20
expiresIn : { type : 'integer' , minimum : 1 , examples : [ 60000 ] } ,
21
+ transform : {
22
+ type : 'object' ,
23
+ properties : transformationOptionsSchema ,
24
+ } ,
20
25
} ,
21
26
required : [ 'expiresIn' ] ,
22
27
} as const
23
- const renderImageQuerySchema = {
24
- type : 'object' ,
25
- properties : {
26
- ...transformationQueryString ,
27
- } ,
28
- } as const
28
+
29
29
const successResponseSchema = {
30
30
type : 'object' ,
31
31
properties : {
@@ -41,16 +41,16 @@ const successResponseSchema = {
41
41
interface getSignedURLRequestInterface extends AuthenticatedRequest {
42
42
Params : FromSchema < typeof getSignedURLParamsSchema >
43
43
Body : FromSchema < typeof getSignedURLBodySchema >
44
- Querystring : FromSchema < typeof renderImageQuerySchema >
45
44
}
46
45
46
+ const { enableImageTransformation } = getConfig ( )
47
+
47
48
export default async function routes ( fastify : FastifyInstance ) {
48
49
const summary = 'Generate a presigned url to retrieve an object'
49
50
50
51
const schema = createDefaultSchema ( successResponseSchema , {
51
52
body : getSignedURLBodySchema ,
52
53
params : getSignedURLParamsSchema ,
53
- querystring : renderImageQuerySchema ,
54
54
summary,
55
55
tags : [ 'object' ] ,
56
56
} )
@@ -70,7 +70,9 @@ export default async function routes(fastify: FastifyInstance) {
70
70
const signedURL = await request . storage
71
71
. from ( bucketName )
72
72
. signObjectUrl ( objectName , urlPath as string , expiresIn , {
73
- transformations : ImageRenderer . applyTransformation ( request . query || { } ) . join ( ',' ) ,
73
+ transformations : enableImageTransformation
74
+ ? ImageRenderer . applyTransformation ( request . body . transform || { } ) . join ( ',' )
75
+ : '' ,
74
76
} )
75
77
76
78
return response . status ( 200 ) . send ( { signedURL } )
0 commit comments