1- import { task } from "@trigger.dev/sdk/v3" ;
1+ import { schemaTask } from "@trigger.dev/sdk/v3" ;
2+ import { z } from "zod" ;
23import { python } from "@trigger.dev/python" ;
34import { promises as fs } from "fs" ;
45import { S3Client } from "@aws-sdk/client-s3" ;
@@ -14,31 +15,53 @@ const s3Client = new S3Client({
1415 } ,
1516} ) ;
1617
17- export const processImage = task ( {
18+ // Define the input schema with Zod
19+ const imageProcessingSchema = z . object ( {
20+ imageUrl : z . string ( ) . url ( ) ,
21+ height : z . number ( ) . positive ( ) . optional ( ) . default ( 800 ) ,
22+ width : z . number ( ) . positive ( ) . optional ( ) . default ( 600 ) ,
23+ quality : z . number ( ) . min ( 1 ) . max ( 100 ) . optional ( ) . default ( 85 ) ,
24+ maintainAspectRatio : z . boolean ( ) . optional ( ) . default ( true ) ,
25+ outputFormat : z . enum ( [ "jpeg" , "png" , "webp" , "gif" , "avif" ] ) . optional ( )
26+ . default ( "jpeg" ) ,
27+ brightness : z . number ( ) . optional ( ) ,
28+ contrast : z . number ( ) . optional ( ) ,
29+ sharpness : z . number ( ) . optional ( ) ,
30+ grayscale : z . boolean ( ) . optional ( ) . default ( false ) ,
31+ } ) ;
32+
33+ // Define the output schema
34+ const outputSchema = z . object ( {
35+ url : z . string ( ) . url ( ) ,
36+ key : z . string ( ) ,
37+ format : z . string ( ) ,
38+ originalSize : z . object ( {
39+ width : z . number ( ) ,
40+ height : z . number ( ) ,
41+ } ) ,
42+ newSize : z . object ( {
43+ width : z . number ( ) ,
44+ height : z . number ( ) ,
45+ } ) ,
46+ fileSizeBytes : z . number ( ) ,
47+ exitCode : z . number ( ) ,
48+ } ) ;
49+
50+ export const processImage = schemaTask ( {
1851 id : "process-image" ,
19- run : async ( payload : {
20- imageUrl : string ;
21- height ?: number ;
22- width ?: number ;
23- quality ?: number ;
24- maintainAspectRatio ?: boolean ;
25- outputFormat ?: "jpeg" | "png" | "webp" | "gif" | "avif" ;
26- brightness ?: number ;
27- contrast ?: number ;
28- sharpness ?: number ;
29- grayscale ?: boolean ;
30- } , io : any ) => {
52+ schema : imageProcessingSchema ,
53+ run : async ( payload , io ) => {
3154 const {
3255 imageUrl,
33- height = 800 ,
34- width = 600 ,
35- quality = 85 ,
36- maintainAspectRatio = true ,
37- outputFormat = "jpeg" ,
56+ height,
57+ width,
58+ quality,
59+ maintainAspectRatio,
60+ outputFormat,
3861 brightness,
3962 contrast,
4063 sharpness,
41- grayscale = false ,
64+ grayscale,
4265 } = payload ;
4366
4467 try {
0 commit comments