Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async resolve({ request }) {
const { id, imageUrl } = request.body.variables.pin;
const { userId } = request.body.variables;
// Let's call Google Machine Vision API
const vision = new Vision({
projectId: "ai-concierge-185823",
keyFilename: config.googley_key_file,
});
const minAccuracy = 0.4;
const req = { source: { imageUri: imageUrl } };
const visionResponse = await vision.landmarkDetection(req);
// check if the machine vision has detected a landmark with good accuracy
const isLandmark = visionResponse[0].landmarkAnnotations.length > 0;
if (!isLandmark) return { pinId: id, detected: false };
const bestGuess = visionResponse[0].landmarkAnnotations[0];
const hasGoodScore = bestGuess.score >= minAccuracy;
if (!hasGoodScore) return { pinId: id, detected: false };
// it's good - we can return a detection with all info
const annotations = visionResponse[0].landmarkAnnotations;
const goodAnnotations = annotations.filter(
anno => anno.score > minAccuracy,