From c9f45ef82f5c7203e99a68c33087c1646e462628 Mon Sep 17 00:00:00 2001 From: Raphix Date: Thu, 23 Mar 2023 18:24:43 +0100 Subject: [PATCH] Add Upload Component for Files Component --- public/stylesheets/style.css | 1 - public/templates/files.html | 65 ++++++++++++++++++- routes/filemanager.js | 2 +- routes/upload.js | 25 +++++++ .../0cee5da6-6812-49d8-97f5-2df5c1d78191.json | 2 +- 5 files changed, 91 insertions(+), 4 deletions(-) diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index b42d335..6f87300 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -298,7 +298,6 @@ body { display: flex; justify-content: start; - gap: 1vw; flex-direction: column; } diff --git a/public/templates/files.html b/public/templates/files.html index c9989cc..8e55fca 100644 --- a/public/templates/files.html +++ b/public/templates/files.html @@ -8,6 +8,7 @@

Fichiers

+
@@ -154,10 +155,72 @@ }) const uploadBtn = document.getElementById("fi_upload") + const uploadFiles = document.getElementById("fi_upload_file") + uploadBtn.addEventListener("click", () => { - document.getElementById("_rename").showModal() + uploadFiles.click() + + }) + + uploadFiles.addEventListener("change", () => { + + var stopSend = false + fiInfo.innerHTML = "" + + for(var file of uploadFiles.files) { + + + + if(stopSend == false) { + const file_acc = new FormData(); + file_acc.append("apic", file) + + fetch('/upload', { + method: 'POST', + mode:"cors", + cache:"no-cache", + credentials:"same-origin", + headers: { + "uploadfiledirectory": currentDir.value + + }, + referrerPolicy:"no-referrer", + redirect: 'follow', + body: file_acc + }).then(response => response.json()) + .then(response => resupload(response)) + + function resupload(response) { + + + if(response.result == "ERROR") { + fiInfo.innerHTML = "Les fichiers n'ont pas pu ĂȘtre uploadĂ©s !" + stopSend = true + + } else { + + getDirectory(currentDir.value) + } + + } + + } + + + + + + } + + uploadFiles.value = null + + + + + + }) currentDir.addEventListener("change", () => { diff --git a/routes/filemanager.js b/routes/filemanager.js index 5194d4c..5fcfc3b 100644 --- a/routes/filemanager.js +++ b/routes/filemanager.js @@ -94,7 +94,7 @@ router.post("/", function(req, res, next) { try { if(file.directory == true) { - fs.rmdirSync(file.fileDirectory) + fs.rmdirSync(file.fileDirectory , { recursive: true, force: true }) } else { fs.rmSync(file.fileDirectory) diff --git a/routes/upload.js b/routes/upload.js index 973adfc..9fcf097 100644 --- a/routes/upload.js +++ b/routes/upload.js @@ -6,6 +6,7 @@ var CryptoJS = require("crypto-js"); var uuid = require("uuid") var ntr = require("../neutral-functions.js"); const Jimp = require("jimp"); +const { compileString } = require('sass'); /* GET home page. */ router.get('/', function(req, res, next) { @@ -37,6 +38,8 @@ router.post("/", function(req, res, next) { const image = req.files.apic + console.log("test") + if(req.headers.uploadforuser != null) { if(check.permLevel == 4) { @@ -133,6 +136,28 @@ router.post("/", function(req, res, next) { } + } else if(req.headers.uploadfiledirectory != null) { + + if(fs.existsSync(req.headers.uploadfiledirectory)) { + image.mv(req.headers.uploadfiledirectory + path.sep + req.files.apic.name, (error) => { + + if(error) { + res.send({"result":"ERROR"}) + + } else { + + res.send({"result":"SUCCESS"}) + } + }) + + + } else { + + res.send({"result":"ERROR"}) + } + + + } else { diff --git a/users/0cee5da6-6812-49d8-97f5-2df5c1d78191.json b/users/0cee5da6-6812-49d8-97f5-2df5c1d78191.json index 72f24ac..df029ad 100644 --- a/users/0cee5da6-6812-49d8-97f5-2df5c1d78191.json +++ b/users/0cee5da6-6812-49d8-97f5-2df5c1d78191.json @@ -9,5 +9,5 @@ "livableToken": true, "createdAt": 1679260759114 }, - "lastconnexion": 1679513878276 + "lastconnexion": 1679592206404 } \ No newline at end of file