S3 for other controolers
This commit is contained in:
@@ -4,7 +4,6 @@ const { rateLimit } = require("express-rate-limit");
|
||||
const bcrypt = require("bcryptjs");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const crypto = require("crypto");
|
||||
const sharp = require("sharp");
|
||||
const { secretKey } = require("./../authentication");
|
||||
const { _sr } = require("../plugins/serverResponses");
|
||||
const {
|
||||
@@ -14,7 +13,10 @@ const {
|
||||
isLatinCharactersWithSymbol,
|
||||
generateRandomDigits,
|
||||
} = require("../plugins/controllersHelperFunctions");
|
||||
const fs = require("fs");
|
||||
const {
|
||||
deleteUserImage,
|
||||
uploadProcessedImage,
|
||||
} = require("../plugins/userImageStorage");
|
||||
const nodemailer = require("nodemailer");
|
||||
const Category = require("../models/Category");
|
||||
const Logger = require("../models/Logger");
|
||||
@@ -566,15 +568,13 @@ module.exports.registerAdmin = [
|
||||
image.mimetype.split("/")[1];
|
||||
data.profilePic = imageName;
|
||||
try {
|
||||
const target = sharp(image.data);
|
||||
await target
|
||||
.resize(profileWidth, profileHeight, {
|
||||
fit: "cover",
|
||||
})
|
||||
.jpeg({
|
||||
quality: profileQuality,
|
||||
})
|
||||
.toFile(`./static/uploads/images/users/${imageName}`);
|
||||
await uploadProcessedImage(
|
||||
image.data,
|
||||
imageName,
|
||||
profileWidth,
|
||||
profileHeight,
|
||||
profileQuality
|
||||
);
|
||||
} catch (e) {
|
||||
return res500(res, e?.message);
|
||||
}
|
||||
@@ -713,18 +713,7 @@ module.exports.deleteOneUser = [
|
||||
.json({ message: `شما نمیتوانید این کاربر را حذف کنید` });
|
||||
}
|
||||
|
||||
/**
|
||||
* if exist old pic delete it from file
|
||||
*/
|
||||
if (user.profilePic) {
|
||||
var oldPic = `./static${user.profilePic}`;
|
||||
|
||||
if (fs.existsSync(oldPic)) {
|
||||
fs.unlink(oldPic, (err) => {
|
||||
if (err) return res500(res, err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
await deleteUserImage(user, "profilePic");
|
||||
|
||||
/** delete user */
|
||||
await user.deleteOne();
|
||||
@@ -922,28 +911,15 @@ module.exports.updateUser = [
|
||||
image.mimetype.split("/")[1];
|
||||
|
||||
try {
|
||||
const target = sharp(image.data);
|
||||
await target
|
||||
.resize(profileWidth, profileHeight, {
|
||||
fit: "cover",
|
||||
})
|
||||
.jpeg({
|
||||
quality: profileQuality,
|
||||
})
|
||||
.toFile(`./static/uploads/images/users/${imageName}`);
|
||||
await deleteUserImage(user, "profilePic");
|
||||
|
||||
/**
|
||||
* if exist old pic delete it from file
|
||||
*/
|
||||
if (user.profilePic) {
|
||||
var oldPic = `./static${user.profilePic}`;
|
||||
|
||||
if (fs.existsSync(oldPic)) {
|
||||
fs.unlink(oldPic, (err) => {
|
||||
if (err) return res500(res, err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
await uploadProcessedImage(
|
||||
image.data,
|
||||
imageName,
|
||||
profileWidth,
|
||||
profileHeight,
|
||||
profileQuality
|
||||
);
|
||||
} catch (e) {
|
||||
return res500(res, e?.message);
|
||||
}
|
||||
@@ -1129,28 +1105,15 @@ module.exports.updateProfile = [
|
||||
image.mimetype.split("/")[1];
|
||||
|
||||
try {
|
||||
const target = sharp(image.data);
|
||||
await target
|
||||
.resize(profileWidth, profileHeight, {
|
||||
fit: "cover",
|
||||
})
|
||||
.jpeg({
|
||||
quality: profileQuality,
|
||||
})
|
||||
.toFile(`./static/uploads/images/users/${imageName}`);
|
||||
await deleteUserImage(user, "profilePic");
|
||||
|
||||
/**
|
||||
* if exist old pic delete it from file
|
||||
*/
|
||||
if (user.profilePic) {
|
||||
var oldPic = `./static${user.profilePic}`;
|
||||
|
||||
if (fs.existsSync(oldPic)) {
|
||||
fs.unlink(oldPic, (err) => {
|
||||
if (err) return res500(res, err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
await uploadProcessedImage(
|
||||
image.data,
|
||||
imageName,
|
||||
profileWidth,
|
||||
profileHeight,
|
||||
profileQuality
|
||||
);
|
||||
} catch (e) {
|
||||
return res500(res, e?.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user