update resizer

This commit is contained in:
solehudin5699
2022-02-27 23:45:18 +07:00
parent 56854725ea
commit 4e16383020
+5 -2
View File
@@ -2,12 +2,12 @@ const sharp = require('sharp');
const fs = require('fs'); const fs = require('fs');
const resizer = async (req, res) => { const resizer = async (req, res) => {
try {
const { width, height, quality, format } = req.query; const { width, height, quality, format } = req.query;
const { filename } = req.params; const { filename } = req.params;
try {
if (width) { if (width) {
if (parseInt(width) > 5000) { if (parseInt(width) > 5000) {
fs.unlinkSync('public/' + filename);
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: 'Error. Width must be <=5000', message: 'Error. Width must be <=5000',
@@ -17,6 +17,7 @@ const resizer = async (req, res) => {
if (height) { if (height) {
if (parseInt(height) > 5000) { if (parseInt(height) > 5000) {
fs.unlinkSync('public/' + filename);
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: 'Error. Height must be <=5000', message: 'Error. Height must be <=5000',
@@ -26,6 +27,7 @@ const resizer = async (req, res) => {
if (quality) { if (quality) {
if (parseInt(quality) > 100) { if (parseInt(quality) > 100) {
fs.unlinkSync('public/' + filename);
return res.status(400).json({ return res.status(400).json({
success: false, success: false,
message: 'Error. Quality must be <=100', message: 'Error. Quality must be <=100',
@@ -54,6 +56,7 @@ const resizer = async (req, res) => {
fs.unlinkSync('public/' + filename); fs.unlinkSync('public/' + filename);
} catch (error) { } catch (error) {
fs.unlinkSync('public/' + filename);
res.setHeader('content-type', 'application/json'); res.setHeader('content-type', 'application/json');
res.status(500).json({ res.status(500).json({
success: false, success: false,