diff --git a/.gitignore b/.gitignore index c2658d7..713d500 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +.env diff --git a/app/components/ImageCapture/ImageCapture.js b/app/components/ImageCapture/ImageCapture.js index 72de174..64f1d3f 100644 --- a/app/components/ImageCapture/ImageCapture.js +++ b/app/components/ImageCapture/ImageCapture.js @@ -67,21 +67,9 @@ console.log('trying to stop video'); ctx.drawImage(video, 350, 20, 600, 700, 0, 0, 300, 350); this.endImageCapture(video); canvas.toBlob((blob) => { - let newImg = document.createElement('img'); - let att = document.createAttribute("class"); - att.value = "user-image"; - newImg.setAttributeNode(att); - let url = URL.createObjectURL(blob); - - newImg.onload = () =>{ - URL.revokeObjectURL(url); - }; - - newImg.src = url; - document.body.appendChild(newImg); - const faceURL = document.querySelector('.user-image').src; - console.log(faceURL); - }) + let faceURL = URL.createObjectURL(blob); + console.log(faceURL); + }) // this.storeData(faceURL); } } diff --git a/package.json b/package.json index 0d656b4..fc01004 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "license": "ISC", "dependencies": { "body-parser": "^1.16.0", + "dotenv": "^4.0.0", "express": "^4.14.0", "express-cors": "0.0.3", "nodemon": "^1.11.0", diff --git a/src/controller.js b/src/controller.js index 2851008..00eec51 100644 --- a/src/controller.js +++ b/src/controller.js @@ -1,18 +1,19 @@ const request = require('request') -const API_KEY = require('./key') -const BASE_URL = `https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize` -const IMAGE_URL = 'localhost:300/image' +require('dotenv').load() +const API_KEY = process.env.EMOTION_API_KEY +const API_URL = `https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize` +const APP_BASE_URL = 'localhost:3000' -function getEmotionAnalysis(req, res, next) { +function getEmotionAnalysis(req, res) { request({ - url: BASE_URL, + url: API_URL, method: 'POST', headers: { 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': API_KEY }, - body: JSON.stringify({url: IMAGE_URL}) + body: JSON.stringify({url: /*IMAGE URL GOES HERE SOMEHOW*/}) }, function (error, response, body) { if (!error && response.statusCode == 200) { @@ -21,6 +22,27 @@ function getEmotionAnalysis(req, res, next) { }) } +function postImageURL(req, res) { //FIGURE OUT HOW TO INSERT FACEURL FROM IMAGECAPTURE + request({ + url: '/API/imageURL', + method: 'POST', + body: JSON.stringify({url: /*FACEURL GOES HERE SOMEHOW!!!*/}) + }) + function (error, response, body) { + if (!error && response.statusCode == 200) { + res.send(body) + } + }) +} + +function getImageURL(req, res) { //FIGURE OUT HOW TO GET THE IMAGE URL FROM THE BACKEND + request({ +//MAGIC HAPPENS HERE????????? + }) +} + module.exports = { - getEmotionAnalysis: getEmotionAnalysis + getEmotionAnalysis: getEmotionAnalysis, + postImageURL: postImageURL, + getImageURL: getImageURL }; diff --git a/src/router.js b/src/router.js index fb618e7..27869d1 100644 --- a/src/router.js +++ b/src/router.js @@ -3,5 +3,7 @@ var router = express.Router(); var controller = require('./controller'); router.post('/emotions', controller.getEmotionAnalysis) + router.post('/API/imageURL', controller.postImageURL) + router.get('/API/imageURL/:url', controller.getImageURL) module.exports = router;