@@ -90,44 +90,38 @@ async function analyzeProductStructured(imageUrl: string) {
9090}
9191
9292export const uploadImageToR2 = task ( {
93- id : "upload-image-to-r2 " ,
94- maxDuration : 300 , // 5 minutes max
93+ id : "upload-image-and-analyze " ,
94+ maxDuration : 300 , // 5 mins
9595 run : async ( payload : {
9696 imageBuffer : string ; // base64 encoded image
9797 fileName : string ;
9898 contentType : string ;
9999 } ) => {
100100 const { imageBuffer, fileName, contentType } = payload ;
101101
102- // Set initial metadata with 5 steps (added analysis)
102+ // Step 1: Start the upload and analysis
103103 metadata . set ( "status" , "starting" ) ;
104104 metadata . set ( "progress" , {
105105 step : 1 ,
106- total : 5 ,
106+ total : 4 ,
107107 message : "Preparing upload and analysis..." ,
108108 } ) ;
109109
110110 logger . log ( "Starting image upload and analysis" , { fileName, contentType } ) ;
111111
112- // Convert base64 to buffer
113- metadata . set ( "progress" , {
114- step : 2 ,
115- total : 5 ,
116- message : "Processing image data..." ,
117- } ) ;
118112 const buffer = Buffer . from ( imageBuffer , "base64" ) ;
119113 const fileSize = buffer . length ;
120114
121115 logger . log ( `Image size: ${ fileSize } bytes` ) ;
122116
123- // Generate unique key for R2
117+ // Step 2: Generate unique key for R2
124118 const timestamp = Date . now ( ) ;
125119 const sanitizedFileName = fileName . replace ( / [ ^ a - z A - Z 0 - 9 . - ] / g, "_" ) ;
126120 const r2Key = `uploaded-images/${ timestamp } -${ sanitizedFileName } ` ;
127121
128122 metadata . set ( "progress" , {
129- step : 3 ,
130- total : 5 ,
123+ step : 2 ,
124+ total : 4 ,
131125 message : "Uploading to storage..." ,
132126 } ) ;
133127
@@ -158,20 +152,20 @@ export const uploadImageToR2 = task({
158152 // Construct the public URL using the R2_PUBLIC_URL env var
159153 const publicUrl = `${ process . env . R2_PUBLIC_URL } /${ r2Key } ` ;
160154
161- // Step 4 : Analyze product properties
155+ // Step 3 : Analyze product properties
162156 metadata . set ( "progress" , {
163- step : 4 ,
164- total : 5 ,
157+ step : 3 ,
158+ total : 4 ,
165159 message : "Analyzing product properties..." ,
166160 } ) ;
167161
168162 const productAnalysis = await analyzeProductStructured ( publicUrl ) ;
169163 logger . log ( "Product analysis completed" , { productAnalysis } ) ;
170164
171- // Step 5 : Complete
165+ // Step 4 : Complete
172166 metadata . set ( "progress" , {
173- step : 5 ,
174- total : 5 ,
167+ step : 4 ,
168+ total : 4 ,
175169 message : "Upload and analysis completed!" ,
176170 } ) ;
177171 metadata . set ( "status" , "completed" ) ;
@@ -200,7 +194,7 @@ export const uploadImageToR2 = task({
200194 metadata . set ( "status" , "failed" ) ;
201195 metadata . set ( "progress" , {
202196 step : 0 ,
203- total : 5 ,
197+ total : 4 ,
204198 message : "Upload and analysis failed" ,
205199 } ) ;
206200 metadata . set (
0 commit comments