import multer from "multer";
import fs from 'fs';

const upload = multer({
    dest: "./temp",
    fileSize: 3072
});

const removeFromFile = (filename, toRemove) => {
    let content = fs.readFileSync(filename).toString();
    let dataArray = content.split('\n');
    let lastIndex = -1;
    for (let i = 0; i < dataArray.length; i ++) {
        if (dataArray[i].includes(toRemove)) {
            lastIndex = i;
            break;
        }
    }
    dataArray.splice(lastIndex, 1);
        const updatedData = dataArray.join('\n');
        fs.writeFileSync(filename, updatedData);
}

export default {upload, removeFromFile};