Skip to content

Instantly share code, notes, and snippets.

@codiini
Created August 1, 2022 19:45
Show Gist options
  • Save codiini/57d1d3b00878c7e5c9e932e16126ff9f to your computer and use it in GitHub Desktop.
Save codiini/57d1d3b00878c7e5c9e932e16126ff9f to your computer and use it in GitHub Desktop.
Restrict explicit content with Gatsby functions
import { collection } from "../utils/mongodb"
export default async function handler(req, res) {
try {
//Accept asset Id to search db for image with a status type of moderation
const moderatedImage = await collection.findOne({
asset_id: req.body.asset_id,
notification_type: "moderation",
})
//if the image is found, return the image
if (moderatedImage && moderatedImage.moderation_status === "approved") {
res.json({
msg: "Image has passed the moderation filter",
status: "approved",
url: moderatedImage.url,
})
} else if (
moderatedImage &&
moderatedImage.moderation_status === "rejected"
) {
res.json({
msg: "Image has been flagged for inappropriate content",
status: "rejected",
})
} else {
res.json({ msg: "Image is still pending moderation..." })
}
} catch (err) {
res.status(500).json({ msg: err.message })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment