Switch to GET, fix forms

GET is much more better than using blobs
This commit is contained in:
2019-05-25 13:37:19 +05:30
parent 57a43aa643
commit aa46296f53
6 changed files with 66 additions and 8 deletions

View File

@@ -18,12 +18,10 @@ app.use(bodyParser.json())
let inDir = (dircheck,dirmain) => !path.relative(path.normalize(dircheck), dirmain).startsWith('..')
//Get folder details
app.post('/files/cat',(req,res,next)=>{
console.log(req.body)
const location = processing.mergedir(req.body.loc,settings)
app.get('/files/cat',(req,res,next)=>{
//console.log(req.body)
const location = processing.mergedir(req.query.loc,settings)
//const nloc = path.normalize(req.body.loc);
const nloc = path.normalize(path.relative(settings.dirname,location))
if(inDir(settings.dirname,location)){
@@ -31,7 +29,6 @@ app.post('/files/cat',(req,res,next)=>{
}
})
app.post('/files/ls',(req,res,next)=>{
const location = processing.mergedir(req.body.loc,settings)
//const nloc = path.normalize(req.body.loc);

29
package-lock.json generated
View File

@@ -119,6 +119,14 @@
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz",
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw=="
},
"busboy": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
"requires": {
"dicer": "0.3.0"
}
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@@ -227,6 +235,14 @@
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"connect-busboy": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/connect-busboy/-/connect-busboy-0.0.2.tgz",
"integrity": "sha1-rFyclmchcYheV2xmsr/ZXTuxEJc=",
"requires": {
"busboy": "*"
}
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
@@ -316,6 +332,14 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
"integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
"requires": {
"streamsearch": "0.1.2"
}
},
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
@@ -1154,6 +1178,11 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",

View File

@@ -26,6 +26,7 @@
"body-parser": "^1.19.0",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"connect-busboy": "0.0.2",
"express": "^4.17.0",
"jquery": "^3.4.1",
"mocha": "^6.1.4"

View File

@@ -20,6 +20,15 @@ input[type="text"]{
border:1px gray solid;
width:5rem;
}
input[type="file"]{
display:none;
}
label[for="fileUpload"]{
padding:0.5rem;
border:1px gray solid;
}
.window{
width:15rem;

View File

@@ -60,12 +60,26 @@ $(document).ready(()=>{
populateContents();
$('.file-download-button').click(()=>{
console.log(currSel)
$.ajax('/files/cat',{
/*$.ajax('/files/cat',{
method:'post',
data:currSel,
xhrFields: {
responseType: 'blob'
},
xhr:()=>{
var xhr = new XMLHttpRequest();
xhr.addEventListener('progress',(ev)=>{
//console.log([ev.loaded,ev.total,ev.lengthComputable])
if(ev.lengthComputable){
$('.file-download-percent').html(`${Math.round(100*ev.loaded/ev.total)}%`)
}
})
xhr.upload.addEventListener('error',(ev)=>{
$('.file-download-percent').html('F')
})
return xhr
},
success:(msg)=>{
//console.log(msg)
$('.file-download-button').after(`<a id="down-temp" href="${window.URL.createObjectURL(msg)}" download="${currSel.name}"></a>`)
@@ -73,7 +87,10 @@ $(document).ready(()=>{
$('#down-temp').remove();
},
error: err=>console.log(err)
})
})*/
$('.file-download-button').after(`<a id="down-temp" href="/files/cat?loc=${currSel.loc}" download="${currSel.name}"></a>`)
document.getElementById('down-temp').click()
$('#down-temp').remove();
})
$('.close-rename').click(()=>{
$('.rename-window').fadeOut('fast')

View File

@@ -20,6 +20,10 @@
<div class="upload-window window box-shadow-2 hidden">
<div class="window-button done-upload"><span class="far fa-check-circle"></span></div>
<div class="window-button close-upload"><span class="far fa-times-circle"></span></div>
<form enctype="multipart/form-data">
<label for="fileInput">Upload file</label>
<input type='file' name="fileUpload" id="fileInput" />
</form>
</div>
</div>
<div class="navbar-container box-shadow-1">
@@ -54,6 +58,7 @@
Select file
</span>
<span class="icon-tabs">
<span class="file-download-percent"></span>
<span class="file-download-button" alt="Download">
<span class="fas fa-file-download"></span>
</span>