File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -34,18 +34,22 @@ import { filterImageFromURL, deleteLocalFiles } from './util/util';
3434 app . get ( '/filteredimage' , async ( req , res ) => {
3535 // Validate the image_url query
3636 if ( ! req . query . image_url ) {
37- res . send ( 'Please use the path to an image in your url.' ) ;
37+ res . status ( 400 ) . send ( 'Please use the path to an image in your url.' ) ;
3838 }
3939
4040 let image_url = req . query . image_url ;
4141
4242 // Call filterImageFromURL(image_url) to filter the image
43- let filteredImage = await filterImageFromURL ( image_url ) ;
44-
45- // Send the resulting file in the response
46- await res . status ( 200 ) . sendFile ( filteredImage ) ;
47- // Deletes any files on the server on finish of the response
48- deleteLocalFiles ( [ filteredImage ] ) ;
43+ filterImageFromURL ( image_url )
44+ // Send the resulting file in the response
45+ . then ( ( result ) => {
46+ res . status ( 200 ) . sendFile ( result ) ;
47+ // Delete any files on the server on finish of the response
48+ res . on ( 'finish' , ( ) => deleteLocalFiles ( [ result ] ) ) ;
49+ } )
50+ . catch ( ( error ) => {
51+ res . status ( error . status ) . send ( error . message ) ;
52+ } ) ;
4953 } ) ;
5054
5155 // Root Endpoint
You can’t perform that action at this time.
0 commit comments