Implement moving
This commit is contained in:
10
index.js
10
index.js
@@ -34,6 +34,7 @@ app.post('/files/ls',(req,res,next)=>{
|
|||||||
//const nloc = path.normalize(req.body.loc);
|
//const nloc = path.normalize(req.body.loc);
|
||||||
// nloc - Path to show the user
|
// nloc - Path to show the user
|
||||||
const nloc = path.normalize(path.relative(settings.dirname,location))
|
const nloc = path.normalize(path.relative(settings.dirname,location))
|
||||||
|
//console.log([loc,nloc])
|
||||||
//Make sure not escaping the given path; insecure
|
//Make sure not escaping the given path; insecure
|
||||||
if(inDir(settings.dirname,location)){
|
if(inDir(settings.dirname,location)){
|
||||||
fs.readdir(location,{withFileTypes:true},(err,files)=>{
|
fs.readdir(location,{withFileTypes:true},(err,files)=>{
|
||||||
@@ -57,15 +58,22 @@ app.post('/files/ls',(req,res,next)=>{
|
|||||||
// Rename / move files
|
// Rename / move files
|
||||||
//loc,nloc
|
//loc,nloc
|
||||||
app.post('/files/mv',(req,res,next)=>{
|
app.post('/files/mv',(req,res,next)=>{
|
||||||
|
//console.log(req.body)
|
||||||
const loc1 = processing.mergedir(req.body.loc,settings)
|
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)
|
const loc2 = processing.mergedir(req.body.nloc,settings)
|
||||||
|
//log([loc1,loc2])
|
||||||
if(inDir(settings.dirname,loc1)&&inDir(settings.dirname,loc2)){
|
if(inDir(settings.dirname,loc1)&&inDir(settings.dirname,loc2)){
|
||||||
fs.rename(loc1,loc2,err=>{
|
fs.rename(loc1,loc2,err=>{
|
||||||
if(err){
|
if(err){
|
||||||
console.log(err)
|
//console.log(err)
|
||||||
next(err)
|
next(err)
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
res.json({'loc':req.body.nloc})
|
res.json({'loc':req.body.nloc})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -13,8 +13,6 @@ function doUpdate(ele,isDir=false){
|
|||||||
$('.nav-bottom-text').html(currSel.name = ele.html())
|
$('.nav-bottom-text').html(currSel.name = ele.html())
|
||||||
|
|
||||||
}
|
}
|
||||||
//$()
|
|
||||||
//$(this).
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateContents(contents){
|
function updateContents(contents){
|
||||||
@@ -57,10 +55,14 @@ function populateContents(){
|
|||||||
// Closing the rename window
|
// Closing the rename window
|
||||||
function closeRenameWindow(){
|
function closeRenameWindow(){
|
||||||
//
|
//
|
||||||
|
$('.rename-window').fadeOut('fast')
|
||||||
|
$("#cover").fadeOut('fast')
|
||||||
}
|
}
|
||||||
// Closing the upload window
|
// Closing the upload window
|
||||||
function closeUploadWindow(){
|
function closeUploadWindow(){
|
||||||
//
|
//
|
||||||
|
$('.upload-window').fadeOut('fast')
|
||||||
|
$("#cover").fadeOut('fast')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +71,7 @@ $(document).ready(()=>{
|
|||||||
$('.file-download-button').click(()=>{
|
$('.file-download-button').click(()=>{
|
||||||
console.log(currSel)
|
console.log(currSel)
|
||||||
if(currSel.loc===null){
|
if(currSel.loc===null){
|
||||||
|
// This shouldn't happen but ok
|
||||||
alert("Please select a file");
|
alert("Please select a file");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -78,14 +81,18 @@ $(document).ready(()=>{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
$('.close-rename').click(()=>{
|
$('.close-rename').click(()=>{
|
||||||
$('.rename-window').fadeOut('fast')
|
closeRenameWindow();
|
||||||
$("#cover").fadeOut('fast')
|
|
||||||
})
|
})
|
||||||
$('.close-upload').click(()=>{
|
$('.close-upload').click(()=>{
|
||||||
$('.upload-window').fadeOut('fast')
|
closeUploadWindow();
|
||||||
$("#cover").fadeOut('fast')
|
|
||||||
})
|
})
|
||||||
$('.file-rename-button').click(()=>{
|
$('.file-rename-button').click(()=>{
|
||||||
|
if(currSel.loc===nul){
|
||||||
|
alert("No file selected")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$("#nloc-input").val(currSel.loc)
|
||||||
|
}
|
||||||
$('#cover').fadeIn('fast')
|
$('#cover').fadeIn('fast')
|
||||||
$('.rename-window').fadeIn('fast')
|
$('.rename-window').fadeIn('fast')
|
||||||
})
|
})
|
||||||
@@ -94,4 +101,28 @@ $(document).ready(()=>{
|
|||||||
$('.upload-window').fadeIn('fast')
|
$('.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")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@@ -11,16 +11,19 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="cover" class="hidden">
|
<div id="cover" class="hidden">
|
||||||
<div class="rename-window window box-shadow-2 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 done-rename"><span class="far fa-check-circle"></span></div>
|
||||||
<div class="window-button close-rename"><span class="far fa-times-circle"></span></div>
|
<div class="window-button close-rename"><span class="far fa-times-circle"></span></div>
|
||||||
<form>
|
<form id="rename-form">
|
||||||
<input type='value' placeholder="New location (Rel.)"/>
|
<input type='value' id="nloc-input"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="upload-window window box-shadow-2 hidden">
|
<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 done-upload"><span class="far fa-check-circle"></span></div>
|
||||||
<div class="window-button close-upload"><span class="far fa-times-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>
|
<label for="fileInput">Upload file</label>
|
||||||
<input type='file' name="fileUpload" id="fileInput" />
|
<input type='file' name="fileUpload" id="fileInput" />
|
||||||
</form>
|
</form>
|
||||||
@@ -53,9 +56,7 @@
|
|||||||
<button class="nav-bottom-button box-shadow-3 box-shadow-3-active">+</button>
|
<button class="nav-bottom-button box-shadow-3 box-shadow-3-active">+</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="nav-bottom box-shadow-3">
|
<div class="nav-bottom box-shadow-3">
|
||||||
<span class="nav-bottom-text">
|
<span class="nav-bottom-text">Select file</span>
|
||||||
Select file
|
|
||||||
</span>
|
|
||||||
<span class="icon-tabs">
|
<span class="icon-tabs">
|
||||||
<span class="file-buttons file-download-button" alt="Download">
|
<span class="file-buttons file-download-button" alt="Download">
|
||||||
<span class="fas fa-file-download"></span>
|
<span class="fas fa-file-download"></span>
|
||||||
|
Reference in New Issue
Block a user