2019-09-12 21:25:02 +05:30
|
|
|
"use strict";
|
2019-05-24 14:41:30 +05:30
|
|
|
let currDir = {'loc':'','contents':null}
|
|
|
|
let currSel = {'loc':null,'name':null}
|
2019-05-21 19:37:11 +05:30
|
|
|
|
2019-09-15 10:55:06 +05:30
|
|
|
function makeLSRequest(location){
|
|
|
|
return {
|
|
|
|
loc: location
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeMVRequest(location,newLocation){
|
|
|
|
return {
|
|
|
|
loc: location,
|
|
|
|
nloc: newLocation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-12 21:25:02 +05:30
|
|
|
|
|
|
|
///Get Path at location
|
|
|
|
async function postLS(inputPath){
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
$.ajax('/files/ls',{
|
|
|
|
method:'post',
|
2019-09-15 10:55:06 +05:30
|
|
|
data: makeLSRequest(inputPath),
|
2019-09-12 21:25:02 +05:30
|
|
|
success:(msg)=>{
|
|
|
|
resolve(msg);
|
|
|
|
},
|
|
|
|
error:(msg)=>{
|
|
|
|
reject("E:"+msg)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///Send request to move/rename files
|
|
|
|
async function postMV(oldLocation,newLocation){
|
|
|
|
return new Promise((resolve,reject)=>{
|
2020-12-05 10:43:11 +05:30
|
|
|
$.ajax('/files/mv',{
|
|
|
|
method:'post',
|
2019-09-15 10:55:06 +05:30
|
|
|
data: makeMVRequest(oldLocation,newLocation),
|
2019-09-12 21:25:02 +05:30
|
|
|
success:response=>{
|
|
|
|
resolve(response)
|
|
|
|
},
|
|
|
|
error:err=>{
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2019-05-22 17:09:45 +05:30
|
|
|
}
|
|
|
|
|
2019-05-22 20:22:59 +05:30
|
|
|
|
2019-09-14 13:31:24 +05:30
|
|
|
///Call for onclick of elements
|
2019-09-12 21:25:02 +05:30
|
|
|
function doUpdate(ele,isDir=false){
|
2019-09-14 19:44:28 +05:30
|
|
|
if(!isDir){
|
|
|
|
currSel.loc = ele.attr('data-choice')
|
|
|
|
$('.nav-bottom-text').html( (currSel.name = ele.html()) )
|
|
|
|
}else{
|
|
|
|
///Check if navigable directory
|
|
|
|
postLS(ele.attr('data-choice')).then(e=>{
|
|
|
|
if(ele.hasClass('file-isDir')){
|
|
|
|
///Set as current directory
|
|
|
|
currDir.loc=ele.attr('data-choice')
|
|
|
|
updateContents(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
err=>{
|
|
|
|
console.log(`E:Something went wrong: ${JSON.stringify(err)}`)
|
2019-09-15 10:55:06 +05:30
|
|
|
})
|
2019-09-14 19:44:28 +05:30
|
|
|
}
|
|
|
|
|
2019-09-12 21:25:02 +05:30
|
|
|
}
|
|
|
|
|
2019-09-14 13:31:24 +05:30
|
|
|
|
|
|
|
///Populate contents
|
2019-09-12 21:25:02 +05:30
|
|
|
function updateContents(contentResponse){
|
2019-09-14 13:31:24 +05:30
|
|
|
///Change top header contents
|
2019-09-12 21:25:02 +05:30
|
|
|
$('#files-location').html(contentResponse.loc)
|
2019-05-22 20:22:59 +05:30
|
|
|
|
|
|
|
// if empty, return null, this shouldnt execute if the server is responding properly but ok
|
2019-09-12 21:25:02 +05:30
|
|
|
if(contentResponse===null) {
|
2019-05-22 20:22:59 +05:30
|
|
|
$('#files-table').append(`<tr><td>null</td><td class="file-handlers"></td></tr>`)
|
2019-09-12 21:25:02 +05:30
|
|
|
}else{
|
2019-05-23 20:23:32 +05:30
|
|
|
$('#files-table').hide().empty();
|
2020-12-05 09:46:24 +05:30
|
|
|
if(contentResponse.contents.length===0){
|
|
|
|
$('#files-table').append(`<tr class="files-row"><td>...No files...</td></tr>`);
|
|
|
|
}else{
|
|
|
|
contentResponse.contents.forEach(element => {
|
|
|
|
$('#files-table').append(`<tr class="files-row box-shadow-1-active"><td onclick="doUpdate($(this),${element.isDir})" class="file-name ${(element.isDir?'file-isDir':'file-isFile')}" data-choice="${element.path}">${element.name}</td></tr>`)
|
|
|
|
});
|
|
|
|
}
|
2019-09-12 21:25:02 +05:30
|
|
|
if(contentResponse.back!==null){
|
|
|
|
$('#files-table').prepend(`<tr class="files-row box-shadow-1-active"><td onclick="doUpdate($(this),true)" class="file-name file-isDir file-isBack" data-choice="${contentResponse.back}">..</td></tr>`)
|
2019-05-22 20:22:59 +05:30
|
|
|
}
|
2019-05-23 20:23:32 +05:30
|
|
|
$('#files-table').fadeIn()
|
2019-05-22 17:09:45 +05:30
|
|
|
}
|
2019-05-21 20:31:41 +05:30
|
|
|
}
|
2019-05-21 19:37:11 +05:30
|
|
|
|
2019-05-26 21:50:08 +05:30
|
|
|
// Closing the rename window
|
|
|
|
function closeRenameWindow(){
|
2019-05-27 10:51:05 +05:30
|
|
|
$('.rename-window').fadeOut('fast')
|
|
|
|
$("#cover").fadeOut('fast')
|
2019-05-26 21:50:08 +05:30
|
|
|
}
|
|
|
|
// Closing the upload window
|
|
|
|
function closeUploadWindow(){
|
|
|
|
//
|
2019-05-27 10:51:05 +05:30
|
|
|
$('.upload-window').fadeOut('fast')
|
|
|
|
$("#cover").fadeOut('fast')
|
2019-05-26 21:50:08 +05:30
|
|
|
}
|
2019-05-21 20:31:41 +05:30
|
|
|
|
|
|
|
|
2020-12-05 10:43:11 +05:30
|
|
|
$(()=>{
|
|
|
|
postLS(".")
|
|
|
|
.then(e=>{updateContents(e)})
|
|
|
|
.catch(err=>console.log(err))
|
2019-09-12 21:25:02 +05:30
|
|
|
//postLS(currDir.loc);
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.file-download-button').on('click',()=>{
|
2019-05-24 14:41:30 +05:30
|
|
|
console.log(currSel)
|
2019-05-26 21:18:04 +05:30
|
|
|
if(currSel.loc===null){
|
2019-05-27 10:51:05 +05:30
|
|
|
// This shouldn't happen but ok
|
2019-05-26 21:18:04 +05:30
|
|
|
alert("Please select a file");
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$('.file-download-button').after(`<a id="down-temp" href="/files/cat?loc=${currSel.loc}" download="${currSel.name}"></a>`)
|
2020-12-05 10:43:11 +05:30
|
|
|
document.getElementById('down-temp').on('click',)
|
2019-05-26 21:18:04 +05:30
|
|
|
$('#down-temp').remove();
|
|
|
|
}
|
2019-05-24 14:41:30 +05:30
|
|
|
})
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.close-rename').on('click',()=>{
|
2019-05-27 10:51:05 +05:30
|
|
|
closeRenameWindow();
|
2019-05-24 21:38:31 +05:30
|
|
|
})
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.close-upload').on('click',()=>{
|
2019-05-27 10:51:05 +05:30
|
|
|
closeUploadWindow();
|
2019-05-24 21:38:31 +05:30
|
|
|
})
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.file-rename-button').on('click',()=>{
|
2019-09-12 21:25:02 +05:30
|
|
|
if(currSel.loc===null){
|
2019-05-27 10:51:05 +05:30
|
|
|
alert("No file selected")
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$("#nloc-input").val(currSel.loc)
|
2020-12-05 10:43:11 +05:30
|
|
|
$('#cover').fadeIn('fast')
|
|
|
|
$('.rename-window').fadeIn('fast')
|
2019-05-27 10:51:05 +05:30
|
|
|
}
|
2019-05-24 21:38:31 +05:30
|
|
|
})
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.nav-bottom-button').on('click',()=>{
|
2019-05-24 21:38:31 +05:30
|
|
|
$('#cover').fadeIn('fast')
|
|
|
|
$('.upload-window').fadeIn('fast')
|
|
|
|
})
|
2019-05-26 21:50:08 +05:30
|
|
|
|
2020-12-05 10:43:11 +05:30
|
|
|
$('.done-rename').on('click',()=>{
|
2019-05-27 10:51:05 +05:30
|
|
|
if(currSel.loc===null){
|
|
|
|
alert("Please select a file");
|
|
|
|
}
|
|
|
|
else{
|
2019-09-12 21:25:02 +05:30
|
|
|
postMV(currSel.loc,$("#nloc-input").val())
|
|
|
|
.then(response=>{
|
2020-12-05 10:43:11 +05:30
|
|
|
postLS(currDir.loc).then(e=>{updateContents(e)})
|
|
|
|
.catch(err=>console.log(err))
|
2019-09-12 21:25:02 +05:30
|
|
|
})
|
|
|
|
.then(response=>{
|
|
|
|
alert("Moved")
|
2019-05-27 10:51:05 +05:30
|
|
|
},
|
2019-09-12 21:25:02 +05:30
|
|
|
err=>{
|
2020-12-05 10:43:11 +05:30
|
|
|
console.log('E',err);
|
2019-09-12 21:25:02 +05:30
|
|
|
alert("Not moved")
|
|
|
|
})
|
|
|
|
.catch(err=>{
|
|
|
|
console.log("E:Something went wrong, very wrong")
|
2019-05-27 10:51:05 +05:30
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-09-12 21:25:02 +05:30
|
|
|
|
2020-12-05 10:43:11 +05:30
|
|
|
$("#fileInput").on('change',(e)=>{
|
2019-05-27 15:07:36 +05:30
|
|
|
console.log(e.target.files)
|
|
|
|
$("#fileLabel").html(e.target.files[0].name);
|
|
|
|
})
|
2020-12-05 10:43:11 +05:30
|
|
|
$(".done-upload").on('click',()=>{
|
2019-05-27 15:49:17 +05:30
|
|
|
$("#fileLabel").html("Uploading")
|
2019-05-27 15:07:36 +05:30
|
|
|
$("#upload-directory").val(currDir.loc)
|
|
|
|
$.ajax("/files/upload",{
|
|
|
|
method: 'post',
|
|
|
|
processData:false,
|
|
|
|
contentType:false,
|
|
|
|
data:new FormData(document.getElementById('upload-form')),
|
|
|
|
success:msg=>{
|
2019-05-27 15:46:27 +05:30
|
|
|
alert("Uploaded")
|
2019-05-27 15:07:36 +05:30
|
|
|
closeUploadWindow();
|
2020-12-05 10:43:11 +05:30
|
|
|
postLS(currDir.loc).then(e=>{updateContents(e)})
|
|
|
|
.catch(err=>console.log(err));
|
2019-05-27 15:07:36 +05:30
|
|
|
},
|
2020-12-05 10:43:11 +05:30
|
|
|
|
2019-05-27 15:07:36 +05:30
|
|
|
error:msg=>alert("Error")
|
2020-12-05 10:43:11 +05:30
|
|
|
}).progress(function (){
|
|
|
|
console.log('prog');
|
|
|
|
// $("#fileLabel").html("Uploading",progress)
|
2019-05-27 15:07:36 +05:30
|
|
|
})
|
|
|
|
})
|
2019-09-12 21:25:02 +05:30
|
|
|
})
|