npm cache clean --force
app.post("/makeFolder", (req, res) => {
res.setHeader("Access-Control-Allow-Origin", "*")
console.log(req.body.files[0])
const id = nanoId(13)
fs.mkdirSync(path.join(__dirname, "uploads", id))
fs.copyFileSync(path.join(__dirname, "uploads", req.body.files[0], "index.json"), path.join(__dirname, "uploads", id))
res.send(JSON.stringify({fuck: true}))
})
if (counter) {
const xmlhttp = new XMLHttpRequest()
xmlhttp.open("POST", "http://localhost:3000/makeFolder", true)
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
xmlhttp.send(JSON.stringify({files: filesArray}))
}
const storage = multer.diskStorage({
destination(req, file, cb) {
const id = nanoId(13)
const folder = `./uploads/${id}`
fs.mkdirSync(folder, {recursive: true})
fs.writeFileSync(folder + '/index.json', JSON.stringify({
file:file.originalname
}))
req.fileUploadId = id;
cb(null,folder)
},
filename(req, file, cb) {
req.fileUploadName = file.originalname
cb(null, file.originalname)
}
})
const upload = multer({storage: storage})