@@ -2,6 +2,8 @@ import { FastifyInstance } from 'fastify'
22import { FromSchema } from 'json-schema-to-ts'
33import { createDefaultSchema } from '../../generic-routes'
44import { AuthenticatedRequest } from '../../request'
5+ import { ImageRenderer } from '../../../storage/renderer'
6+ import { transformationQueryString } from '../../schemas/transformations'
57
68const getSignedURLParamsSchema = {
79 type : 'object' ,
@@ -18,6 +20,12 @@ const getSignedURLBodySchema = {
1820 } ,
1921 required : [ 'expiresIn' ] ,
2022} as const
23+ const renderImageQuerySchema = {
24+ type : 'object' ,
25+ properties : {
26+ ...transformationQueryString ,
27+ } ,
28+ } as const
2129const successResponseSchema = {
2230 type : 'object' ,
2331 properties : {
@@ -33,6 +41,7 @@ const successResponseSchema = {
3341interface getSignedURLRequestInterface extends AuthenticatedRequest {
3442 Params : FromSchema < typeof getSignedURLParamsSchema >
3543 Body : FromSchema < typeof getSignedURLBodySchema >
44+ Querystring : FromSchema < typeof renderImageQuerySchema >
3645}
3746
3847export default async function routes ( fastify : FastifyInstance ) {
@@ -41,6 +50,7 @@ export default async function routes(fastify: FastifyInstance) {
4150 const schema = createDefaultSchema ( successResponseSchema , {
4251 body : getSignedURLBodySchema ,
4352 params : getSignedURLParamsSchema ,
53+ querystring : renderImageQuerySchema ,
4454 summary,
4555 tags : [ 'object' ] ,
4656 } )
@@ -55,9 +65,13 @@ export default async function routes(fastify: FastifyInstance) {
5565 const objectName = request . params [ '*' ]
5666 const { expiresIn } = request . body
5767
68+ const urlPath = request . url . split ( '?' ) . shift ( )
69+
5870 const signedURL = await request . storage
5971 . from ( bucketName )
60- . signObjectUrl ( objectName , request . url , expiresIn )
72+ . signObjectUrl ( objectName , urlPath as string , expiresIn , {
73+ transformations : ImageRenderer . applyTransformation ( request . query || { } ) . join ( ',' ) ,
74+ } )
6175
6276 return response . status ( 200 ) . send ( { signedURL } )
6377 }
0 commit comments