From 800233de8ae25f1f5170a6a684aff71b6862aa9c Mon Sep 17 00:00:00 2001 From: Swift Date: Thu, 8 Feb 2024 12:49:58 +0330 Subject: [PATCH] add --- .gitignore | 3 +-- server/controllers/brandController.js | 17 +++++++++++++++-- static/uploads/images/announcement/readme.md | 0 static/uploads/images/brands/readme.md | 1 + static/uploads/images/downloads/readme.md | 0 static/uploads/images/tickets/readme.md | 0 static/uploads/images/warrantyTerms/readme.md | 0 static/uploads/serials/readme.md | 0 static/uploads/serials_products/readme.md | 0 9 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 static/uploads/images/announcement/readme.md create mode 100644 static/uploads/images/brands/readme.md create mode 100644 static/uploads/images/downloads/readme.md create mode 100644 static/uploads/images/tickets/readme.md create mode 100644 static/uploads/images/warrantyTerms/readme.md create mode 100644 static/uploads/serials/readme.md create mode 100644 static/uploads/serials_products/readme.md diff --git a/.gitignore b/.gitignore index f9d3f53..c8c19c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ - -/static/uploads/ +*.xlsx # Created by .ignore support plugin (hsz.mobi) ### Node template # Logs diff --git a/server/controllers/brandController.js b/server/controllers/brandController.js index 8d42691..3365660 100644 --- a/server/controllers/brandController.js +++ b/server/controllers/brandController.js @@ -12,13 +12,26 @@ const createbrand = [ body('title').notEmpty().withMessage(_sr.fa.required.title), body('description').notEmpty().withMessage(_sr.fa.required.description), body('link').notEmpty().trim().isLowercase().withMessage(_sr.fa.required.field), - body('logo').notEmpty().withMessage(_sr.fa.required.image), ], checkValidations(validationResult), async (req, res) => { - const { title, link, description, logo } = req.body; + if (req.files?.image) { + const image = req.files.image + const fileName = 'brands' + Date.now() + '.' + image.name + const acceptableFormats = ['png', 'jpg', 'jpeg', 'webp'] + if (!acceptableFormats.includes(image.mimetype.split('/')[1])) + return res.status(422).json({ validation: { image: { msg: _faSr.format.image } } }) + if (image.size / 1024 > maxAttachmentSize) + return res + .status(422) + .json({ validation: { image: { msg: `حجم تصویر نباید بیشتر از ${maxAttachmentSize} KB باشد.` } } }) + data.image = fileName + await image.mv(`./static/uploads/images/brands/${fileName}`) + } + + const { title, link, description } = req.body; const linkAvailable = await Brand.findOne({ link }); diff --git a/static/uploads/images/announcement/readme.md b/static/uploads/images/announcement/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/static/uploads/images/brands/readme.md b/static/uploads/images/brands/readme.md new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/static/uploads/images/brands/readme.md @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/static/uploads/images/downloads/readme.md b/static/uploads/images/downloads/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/static/uploads/images/tickets/readme.md b/static/uploads/images/tickets/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/static/uploads/images/warrantyTerms/readme.md b/static/uploads/images/warrantyTerms/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/static/uploads/serials/readme.md b/static/uploads/serials/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/static/uploads/serials_products/readme.md b/static/uploads/serials_products/readme.md new file mode 100644 index 0000000..e69de29