Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
.env
temp
temp


#IDE
.idea/*
3 changes: 3 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

#IDE
.idea/*
9 changes: 5 additions & 4 deletions controllers/postController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports.createPost = async (req, res, next) => {
const user = res.locals.user;
const { caption, filter: filterName } = req.body;
let post = undefined;
let cloudinaryResponse = undefined;
const filterObject = filters.find((filter) => filter.name === filterName);
const hashtags = [];
linkify.find(caption).forEach((result) => {
Expand All @@ -43,14 +44,14 @@ module.exports.createPost = async (req, res, next) => {
});

try {
const response = await cloudinary.uploader.upload(req.file.path);
cloudinaryResponse = await cloudinary.uploader.upload(req.file.path);
} catch {
return next({ message: 'Error uploading image, please try again later.' });
}

try {
const moderationResponse = await axios.get(
`https://api.moderatecontent.com/moderate/?key=${process.env.MODERATECONTENT_API_KEY}&url=${response.secure_url}`
`https://api.moderatecontent.com/moderate/?key=${process.env.MODERATECONTENT_API_KEY}&url=${cloudinaryResponse.secure_url}`
);

if (moderationResponse.data.error) {
Expand All @@ -66,7 +67,7 @@ module.exports.createPost = async (req, res, next) => {
}

const thumbnailUrl = formatCloudinaryUrl(
response.secure_url,
cloudinaryResponse.secure_url,
{
width: 400,
height: 400,
Expand All @@ -75,7 +76,7 @@ module.exports.createPost = async (req, res, next) => {
);
fs.unlinkSync(req.file.path);
post = new Post({
image: response.secure_url,
image: cloudinaryResponse.secure_url,
thumbnail: thumbnailUrl,
filter: filterObject ? filterObject.filter : '',
caption,
Expand Down