Skip to content

Commit 1351dc6

Browse files
committed
Generate the request for a filtered image
Following the TODO instructions the image url is extracted from the query and there is a check that it exists. The url is then passed through the filter. The filtered image is then send and deleted from the local system.
1 parent 47add9b commit 1351dc6

File tree

1 file changed

+17
-1
lines changed
  • course-02/project/image-filter-starter-code/src

1 file changed

+17
-1
lines changed

course-02/project/image-filter-starter-code/src/server.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {filterImageFromURL, deleteLocalFiles} from './util/util';
2121
// GET /filteredimage?image_url={{URL}}
2222
// endpoint to filter an image from a public url.
2323
// IT SHOULD
24-
// 1
2524
// 1. validate the image_url query
2625
// 2. call filterImageFromURL(image_url) to filter the image
2726
// 3. send the resulting file in the response
@@ -34,6 +33,23 @@ import {filterImageFromURL, deleteLocalFiles} from './util/util';
3433
/**************************************************************************** */
3534

3635
//! END @TODO1
36+
app.get("/filteredimage", async (req, res) => {
37+
38+
// Task 1 - check that there is a query
39+
const imageUrl: string = await req.query.image_url
40+
if (imageUrl === "") {
41+
return res.status(400).send("You need to include a query url.")
42+
}
43+
44+
// Task 2 - pass the valid image's url through the filter provided
45+
const filteredImage = await filterImageFromURL(imageUrl)
46+
47+
// Task 3 - Send the filtered image in the response
48+
res.sendFile(filteredImage, () => {
49+
// Task 4 - delete the files saved locally
50+
deleteLocalFiles([filteredImage])
51+
})
52+
})
3753

3854
// Root Endpoint
3955
// Displays a simple message to the user

0 commit comments

Comments
 (0)