-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
3,544 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace CreateSearchIndex; | ||
|
||
public class Recipe | ||
{ | ||
public string Name { get; set; } | ||
|
||
public List<string> Steps { get; set; } | ||
|
||
public List<string> IngredientsWithQuantity { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,72 @@ | ||
var request = require('request'); | ||
const fs = require("fs") | ||
|
||
const token = "275027b62452734123aa166829ecffa1ada17ecb" | ||
|
||
/** | ||
* @function CreateRecipie | ||
* @function extractIngredients | ||
* @param req | ||
* @param res | ||
*/ | ||
const extraIngredients = async (req, res) => { | ||
return res.send("Do your magic"); | ||
|
||
/** | ||
* Frontend Developer Notes: Pass the image and enctype as form data | ||
* Example: 'fridge_image': { | ||
'value': fs.createReadStream('/image.jpeg'), | ||
'options': { | ||
'filename': 'image.jpeg', | ||
'contentType': null | ||
} | ||
}, | ||
'enctype': 'multipart/form-data' | ||
*/ | ||
|
||
const extractIngredients = async (req, res) => { | ||
try { | ||
var options = { | ||
'method': 'POST', | ||
'url': 'https://api.logmeal.es/v2/image/segmentation/complete', | ||
'headers': { | ||
'Authorization': `Bearer ${token}` | ||
}, | ||
formData: { | ||
'image': { | ||
'value': fs.createReadStream(req.file.path), | ||
'options': { | ||
'filename': 'image.jpeg', | ||
'contentType': null | ||
} | ||
} | ||
} | ||
}; | ||
|
||
request(options, function (error, response) { | ||
if (response.statusCode != 200) { | ||
return res.status(response.statusCode).send({error: response.body}); | ||
} | ||
|
||
var options = { | ||
'method': 'POST', | ||
'url': 'https://api.logmeal.es/v2/recipe/ingredients', | ||
'headers': { | ||
'Authorization': `Bearer ${token}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ | ||
"imageId": JSON.parse(response.body).imageId | ||
}) | ||
}; | ||
|
||
request(options, (error, response) => { | ||
parsedData = JSON.parse(response.body).foodName | ||
return res.status(200).send({foodItems: parsedData}); | ||
}); | ||
}); | ||
} catch(err) { | ||
return res.status(500).send({error: "Server glitch" + err}); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
extraIngredients | ||
extractIngredients | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
const { promisify } = require('util'); | ||
var exec = promisify(require('child_process').exec) | ||
|
||
/** | ||
* @function CreateRecipie | ||
* @param req | ||
* @param res | ||
*/ | ||
const CreateRecipie = async (req, res) => { | ||
return res.send("Do your magic"); | ||
}; | ||
|
||
/** | ||
* Frontend Developer Notes: Pass foodItems in the body. | ||
* Example: body: { foodItem: ["lettuce", "beef", "tomatoes", "beans"]} | ||
*/ | ||
const CreateRecipie = async (req, res) => { | ||
try { | ||
const ingredients = req.body.foodItems ? req.body.foodItems.join(" ") : "tomatoes pasta meat" | ||
exec("/Users/maryem/Documents/Archive/CreateSearchIndex " + `${ingredients}`, function(error, stdout, stderr) { | ||
return res.status(200).send(JSON.parse(stdout)) | ||
}); | ||
} catch (err) { | ||
return res.status(500).send({error: "server glitch"}) | ||
} | ||
} | ||
module.exports = { | ||
CreateRecipie, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const multer = require("multer"); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
cb(null, 'uploads'); | ||
}, | ||
filename: (req, file, cb) => { | ||
cb(null, file.originalname) | ||
} | ||
}); | ||
|
||
const upload = multer({ | ||
storage: storage, | ||
limits: { | ||
fileSize: 1024 * 1024 * 5 // max 1mb for image size | ||
} | ||
}); | ||
|
||
module.exports = upload; |
Oops, something went wrong.