Add Download Component for Files Component
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
This commit is contained in:
parent
c9f45ef82f
commit
7877729100
2
app.js
2
app.js
@ -20,6 +20,7 @@ var uploadRouter = require('./routes/upload');
|
|||||||
var userManagerRouter = require('./routes/usermanager');
|
var userManagerRouter = require('./routes/usermanager');
|
||||||
var linkRouter = require('./routes/link');
|
var linkRouter = require('./routes/link');
|
||||||
var fileRouter = require("./routes/filemanager")
|
var fileRouter = require("./routes/filemanager")
|
||||||
|
var downloadRouter = require("./routes/download")
|
||||||
|
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
@ -47,6 +48,7 @@ app.use('/upload', uploadRouter)
|
|||||||
app.use('/usermanager', userManagerRouter)
|
app.use('/usermanager', userManagerRouter)
|
||||||
app.use('/link', linkRouter)
|
app.use('/link', linkRouter)
|
||||||
app.use("/filemanager", fileRouter)
|
app.use("/filemanager", fileRouter)
|
||||||
|
app.use("/download", downloadRouter)
|
||||||
|
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
|
@ -478,7 +478,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fileExplorerList.push('<div id="' + file.name + '_directory" class="fi_file row"> <p class="col-lg">' + icon+ '</i> ' + file.name + '</p> <p class="col-lg"><i class="fa fa-calendar"></i> Dernière édition : ' + lastedition + '</p> <p class="col-lg"><i class="fas fa-weight-hanging"></i> Taille : ' + file.size + ' octet(s)</p> <div class="col-lg fi_file_btn"> <button id="' + file.name + '_rename" class="fi_rename"><i id="' + file.name + '_trename" class="fas fa-terminal"></i></button> <button id="' + file + '_download" class="fi_rename"><i id="' + file.name + '_tdownload" class="fas fa-download"></i></button><button id="' + file.name + '_delete" class="fi_delete"><i id="' + file.name + '_tdelete" class="fa fa-trash"></i></button> </div> </div>')
|
fileExplorerList.push('<div id="' + file.name + '_directory" class="fi_file row"> <p class="col-lg">' + icon+ '</i> ' + file.name + '</p> <p class="col-lg"><i class="fa fa-calendar"></i> Dernière édition : ' + lastedition + '</p> <p class="col-lg"><i class="fas fa-weight-hanging"></i> Taille : ' + file.size + ' octet(s)</p> <div class="col-lg fi_file_btn"> <button id="' + file.name + '_rename" class="fi_rename"><i id="' + file.name + '_trename" class="fas fa-terminal"></i></button> <button id="' + file.name + '_download" class="fi_rename"><i id="' + file.name + '_tdownload" class="fas fa-download"></i></button><button id="' + file.name + '_delete" class="fi_delete"><i id="' + file.name + '_tdelete" class="fa fa-trash"></i></button> </div> </div>')
|
||||||
dialogExlorerList.push(' <dialog class="fi_addfolder" id="' + file.name + '_rename_dialog"> <h1><i class="fa fa-terminal"></i> Renommer un fichier</h1> <p><span id="' + file.name + '_old_name"></span></p> <p>Nouveau lien :</p> <input class="inp" id="' + file.name + '_rename_name" type="text"> </div> <p id="' + file.name +'_rename_info" style="text-align: start; color: rgb(255, 48, 48);"></p><button id="' + file.name + '_rename_close" class="fi_add_close">Annuler</button> <button id="' + file.name + '_rename_confirm" class="fi_add_confirm">Editer</button> </dialog>')
|
dialogExlorerList.push(' <dialog class="fi_addfolder" id="' + file.name + '_rename_dialog"> <h1><i class="fa fa-terminal"></i> Renommer un fichier</h1> <p><span id="' + file.name + '_old_name"></span></p> <p>Nouveau lien :</p> <input class="inp" id="' + file.name + '_rename_name" type="text"> </div> <p id="' + file.name +'_rename_info" style="text-align: start; color: rgb(255, 48, 48);"></p><button id="' + file.name + '_rename_close" class="fi_add_close">Annuler</button> <button id="' + file.name + '_rename_confirm" class="fi_add_confirm">Editer</button> </dialog>')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,6 +568,39 @@
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const downloadBtn = document.getElementById(file.name + "_download")
|
||||||
|
|
||||||
|
downloadBtn.addEventListener("click", () => {
|
||||||
|
|
||||||
|
fiInfo.innerHTML = ""
|
||||||
|
|
||||||
|
fetch('/download', {
|
||||||
|
method: 'GET',
|
||||||
|
redirect: 'follow',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'FileRequest': file.fileDirectory
|
||||||
|
}
|
||||||
|
}).then(resp => resp.blob())
|
||||||
|
.then(blob => {
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.style.display = "none";
|
||||||
|
a.href = url;
|
||||||
|
a.download = file.name;
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch(() => fiInfo.innerHTML = "Une erreur est survenue lors du téléchargement");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteBtn.addEventListener("click", () => {
|
deleteBtn.addEventListener("click", () => {
|
||||||
|
48
routes/download.js
Normal file
48
routes/download.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
var express = require('express');
|
||||||
|
var router = express.Router();
|
||||||
|
var ntr = require("../neutral-functions.js");
|
||||||
|
var fs = require("fs")
|
||||||
|
var path = require("path")
|
||||||
|
|
||||||
|
router.get("/", function(req,res,next) {
|
||||||
|
|
||||||
|
var check = ntr.checkToken(req, res)
|
||||||
|
|
||||||
|
if(check.name != false) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(req.headers.filerequest != null && check.permLevel >= 3) {
|
||||||
|
if(fs.existsSync(req.headers.filerequest)) {
|
||||||
|
|
||||||
|
res.download(req.headers.filerequest, (error) => {
|
||||||
|
|
||||||
|
if(error) {
|
||||||
|
|
||||||
|
res.send({"result":"ERROR"})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
res.send({"result":"ERROR"})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
res.redirect("/")
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
res.render('login', {error: ""});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
|
|
@ -9,5 +9,5 @@
|
|||||||
"livableToken": true,
|
"livableToken": true,
|
||||||
"createdAt": 1679260759114
|
"createdAt": 1679260759114
|
||||||
},
|
},
|
||||||
"lastconnexion": 1679592206404
|
"lastconnexion": 1679594165151
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user