diff --git a/index.js b/index.js index e7e6084..d51932a 100644 --- a/index.js +++ b/index.js @@ -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}) + } }) } }) diff --git a/static/base.js b/static/base.js index 05ebd3f..e3fe639 100644 --- a/static/base.js +++ b/static/base.js @@ -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") + } + }) + } + }) }) diff --git a/static/index.html b/static/index.html index 8f6aa5d..20c7111 100644 --- a/static/index.html +++ b/static/index.html @@ -11,16 +11,19 @@