Implement moving

This commit is contained in:
2019-05-27 10:51:05 +05:30
parent bed5762657
commit dcbe68a27f
3 changed files with 54 additions and 14 deletions

View File

@@ -34,6 +34,7 @@ app.post('/files/ls',(req,res,next)=>{
//const nloc = path.normalize(req.body.loc);
// nloc - Path to show the user
const nloc = path.normalize(path.relative(settings.dirname,location))
//console.log([loc,nloc])
//Make sure not escaping the given path; insecure
if(inDir(settings.dirname,location)){
fs.readdir(location,{withFileTypes:true},(err,files)=>{
@@ -57,15 +58,22 @@ app.post('/files/ls',(req,res,next)=>{
// Rename / move files
//loc,nloc
app.post('/files/mv',(req,res,next)=>{
//console.log(req.body)
const loc1 = processing.mergedir(req.body.loc,settings)
if(path.normalize(loc1).startsWith('.')) {
next(new Error("Cannot find dir"))
}
const loc2 = processing.mergedir(req.body.nloc,settings)
//log([loc1,loc2])
if(inDir(settings.dirname,loc1)&&inDir(settings.dirname,loc2)){
fs.rename(loc1,loc2,err=>{
if(err){
console.log(err)
//console.log(err)
next(err)
}
res.json({'loc':req.body.nloc})
else{
res.json({'loc':req.body.nloc})
}
})
}
})

View File

@@ -13,8 +13,6 @@ function doUpdate(ele,isDir=false){
$('.nav-bottom-text').html(currSel.name = ele.html())
}
//$()
//$(this).
}
function updateContents(contents){
@@ -57,10 +55,14 @@ function populateContents(){
// Closing the rename window
function closeRenameWindow(){
//
$('.rename-window').fadeOut('fast')
$("#cover").fadeOut('fast')
}
// Closing the upload window
function closeUploadWindow(){
//
$('.upload-window').fadeOut('fast')
$("#cover").fadeOut('fast')
}
@@ -69,6 +71,7 @@ $(document).ready(()=>{
$('.file-download-button').click(()=>{
console.log(currSel)
if(currSel.loc===null){
// This shouldn't happen but ok
alert("Please select a file");
}
else{
@@ -78,14 +81,18 @@ $(document).ready(()=>{
}
})
$('.close-rename').click(()=>{
$('.rename-window').fadeOut('fast')
$("#cover").fadeOut('fast')
closeRenameWindow();
})
$('.close-upload').click(()=>{
$('.upload-window').fadeOut('fast')
$("#cover").fadeOut('fast')
closeUploadWindow();
})
$('.file-rename-button').click(()=>{
if(currSel.loc===nul){
alert("No file selected")
}
else{
$("#nloc-input").val(currSel.loc)
}
$('#cover').fadeIn('fast')
$('.rename-window').fadeIn('fast')
})
@@ -94,4 +101,28 @@ $(document).ready(()=>{
$('.upload-window').fadeIn('fast')
})
$('.done-rename').click(()=>{
if(currSel.loc===null){
alert("Please select a file");
}
else{
$.ajax("/files/mv",{
method:"post",
data:{
loc:currSel.loc,
nloc:$("#nloc-input").val()
},
success:(msg)=>{
console.log(msg)
populateContents()
alert('Moved')
},
error:msg=>{
console.log(msg)
populateContents()
alert("Could not move")
}
})
}
})
})

View File

@@ -11,16 +11,19 @@
<body>
<div id="cover" class="hidden">
<div class="rename-window window box-shadow-2 hidden">
<span class="window-headers">Move file</span>
<br />
<div class="window-button done-rename"><span class="far fa-check-circle"></span></div>
<div class="window-button close-rename"><span class="far fa-times-circle"></span></div>
<form>
<input type='value' placeholder="New location (Rel.)"/>
<form id="rename-form">
<input type='value' id="nloc-input"/>
</form>
</div>
<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">
<form enctype="multipart/form-data" id="upload-form">
<input hidden='true' type="value" name="loc" />
<label for="fileInput">Upload file</label>
<input type='file' name="fileUpload" id="fileInput" />
</form>
@@ -53,9 +56,7 @@
<button class="nav-bottom-button box-shadow-3 box-shadow-3-active">+</button>
</div>
<div class="nav-bottom box-shadow-3">
<span class="nav-bottom-text">
Select file
</span>
<span class="nav-bottom-text">Select file</span>
<span class="icon-tabs">
<span class="file-buttons file-download-button" alt="Download">
<span class="fas fa-file-download"></span>