Skip to content

Commit

Permalink
Merge pull request #5 from letakeane/lk-createEndpoint
Browse files Browse the repository at this point in the history
WIP: Begin setting up API endpoints - will close Issues #3, #7
  • Loading branch information
letakeane authored May 30, 2017
2 parents a4a3118 + c5c278b commit f68d947
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
.env
18 changes: 3 additions & 15 deletions app/components/ImageCapture/ImageCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 29 additions & 7 deletions src/controller.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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
};
2 changes: 2 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit f68d947

Please sign in to comment.