Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// determining if the picture is safe to show
const safeSearch = response.safeSearchAnnotation;
const isSafe = ["adult", "spoof", "medical", "violence", "racy"].every(k =>
!['LIKELY', 'VERY_LIKELY'].includes(safeSearch[k]));
console.log(`Safe? ${isSafe}`);
// if the picture is safe to display, store it in Firestore
if (isSafe) {
const pictureStore = new Firestore().collection('pictures');
const doc = pictureStore.doc(filename);
await doc.set({
labels: labels,
color: colorHex,
created: Firestore.Timestamp.now()
}, {merge: true});
console.log("Stored metadata in Firestore");
}
} else {
throw new Error(`Vision API error: code ${response.error.code}, message: "${response.error.message}"`);
}
};
public value(): any {
const values: DocumentData = this.rawValue()
const updatedAt: (keyof DocumentData) = "updatedAt"
const createdAt: (keyof DocumentData) = "createdAt"
values[updatedAt] = this.updatedAt || FirebaseFirestore.Timestamp.fromDate(new Date())
values[createdAt] = this.createdAt || FirebaseFirestore.Timestamp.fromDate(new Date())
return values
}
public value(): any {
const values: DocumentData = this.rawValue()
const updatedAt: (keyof DocumentData) = "updatedAt"
const createdAt: (keyof DocumentData) = "createdAt"
values[updatedAt] = this.updatedAt || FirebaseFirestore.Timestamp.fromDate(new Date())
values[createdAt] = this.createdAt || FirebaseFirestore.Timestamp.fromDate(new Date())
return values
}
function isTimestamp(arg) {
return (arg instanceof firebase.firestore.Timestamp) || (arg instanceof FirebaseFirestore.Timestamp);
}
exports.isTimestamp = isTimestamp;