smart-brain-api/controllers/image.js
2022-01-01 10:01:04 -05:00

29 lines
776 B
JavaScript

const Clarifai = require("clarifai"); // Face detection model API
const app = new Clarifai.App({
apiKey: process.env.API_CLARIFAI,
});
const handleApiCall = (req, res) => {
app.models
.predict(Clarifai.FACE_DETECT_MODEL, req.body.input)
.then((data) => {
res.json(data);
})
.catch((err) => res.status(400).json("Unable to work with API."));
};
const handleImage = (req, res, db) => {
const { id } = req.body;
db("users")
.where("id", "=", id)
.increment("entries", 1) // "entries" is the total number of image uploads the user has made
.returning("entries")
.then((entries) => res.json(entries[0]))
.catch((err) => res.status(400).json("Unable to get entries."));
};
module.exports = {
handleImage: handleImage,
handleApiCall: handleApiCall,
};