2018-04-22 07:11:11 +00:00
|
|
|
var pathNodes = [];
|
2018-04-16 01:59:09 +00:00
|
|
|
|
2018-04-23 01:43:19 +00:00
|
|
|
// SSE events if supported
|
|
|
|
if(typeof(EventSource) !== "undefined") {
|
|
|
|
var source = new EventSource("resources/php/sse.php");
|
|
|
|
source.onmessage = function(event) {
|
|
|
|
if (event.data === "updateListing") {
|
|
|
|
getDir("./");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
console.log("SSE Not Supported In Browser...");
|
|
|
|
}
|
|
|
|
|
2018-04-16 01:59:09 +00:00
|
|
|
function getDir(query) {
|
2018-04-23 01:43:19 +00:00
|
|
|
var formUlPth = document.getElementById("DIRPATHUL");
|
2018-04-16 01:59:09 +00:00
|
|
|
var path = "";
|
2018-04-23 01:43:19 +00:00
|
|
|
var cookies = "";
|
|
|
|
var dirCookie = "";
|
2018-04-16 01:59:09 +00:00
|
|
|
|
|
|
|
// push or pop to path list
|
|
|
|
if (query === "/") {
|
2018-04-22 06:03:43 +00:00
|
|
|
// Process path from cookie and set to array/list
|
2018-04-23 01:43:19 +00:00
|
|
|
dirCookie = getCookie("dirQuery");
|
|
|
|
if (dirCookie != "" && dirCookie != "./") {
|
|
|
|
dirCookie = dirCookie.split("/");
|
|
|
|
dirCookie.pop(); // account for ending empty slot
|
2018-04-16 01:59:09 +00:00
|
|
|
|
2018-04-23 01:43:19 +00:00
|
|
|
var size = dirCookie.length;
|
2018-04-16 01:59:09 +00:00
|
|
|
for (var i = 0; i < size; i++) {
|
2018-04-23 01:43:19 +00:00
|
|
|
pathNodes.push(dirCookie[i] + "/");
|
2018-04-16 01:59:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-23 01:43:19 +00:00
|
|
|
pathNodes = [];
|
2018-04-22 08:14:40 +00:00
|
|
|
pathNodes.push("." + query);
|
2018-04-16 01:59:09 +00:00
|
|
|
}
|
|
|
|
} else if (query === "../") {
|
2018-04-22 08:14:40 +00:00
|
|
|
// Only remove while not in root
|
|
|
|
if (pathNodes.length > 1) {
|
|
|
|
pathNodes.pop();
|
|
|
|
}
|
|
|
|
} else if (query === "./") {
|
|
|
|
// Do nothing since re-scanning dir
|
|
|
|
} else {
|
|
|
|
pathNodes.push(query); // Add path
|
|
|
|
}
|
2018-04-16 01:59:09 +00:00
|
|
|
|
|
|
|
// Create path from array of items
|
2018-04-22 08:14:40 +00:00
|
|
|
for (pathNode of pathNodes) {
|
2018-04-23 01:43:19 +00:00
|
|
|
path += pathNode;
|
2018-04-22 07:11:11 +00:00
|
|
|
}
|
2018-04-16 01:59:09 +00:00
|
|
|
|
2018-04-23 01:43:19 +00:00
|
|
|
formUlPth.value = path; // Setup upload path for form
|
2018-04-16 01:59:09 +00:00
|
|
|
path = "dirQuery=" + path;
|
|
|
|
process(path);
|
|
|
|
}
|
|
|
|
|
2018-04-22 06:03:43 +00:00
|
|
|
// Get dir info...
|
2018-04-16 01:59:09 +00:00
|
|
|
function process(path) {
|
|
|
|
var xhttp = new XMLHttpRequest(); // Create the xhttp object
|
|
|
|
|
|
|
|
// This is actually run after open and send are done
|
|
|
|
xhttp.onreadystatechange = function() {
|
|
|
|
if (this.readyState === 4 && this.status === 200) {
|
|
|
|
// Send the returned data to further process
|
2018-04-20 10:51:39 +00:00
|
|
|
if (this.responseXML != null) {
|
2018-04-22 06:03:43 +00:00
|
|
|
updateHTMLDirList(this.responseXML);
|
2018-04-20 10:51:39 +00:00
|
|
|
} else {
|
|
|
|
document.getElementById('dynDiv').innerHTML =
|
|
|
|
"<p class=\"error\" style=\"width:100%;text-align:center;\"> "
|
|
|
|
+ "No content returned. Check the folder path.</p>";
|
|
|
|
}
|
2018-04-16 01:59:09 +00:00
|
|
|
}
|
|
|
|
};
|
2018-04-23 01:43:19 +00:00
|
|
|
xhttp.open("POST", "resources/php/getDirList.php", true); // Open the connection
|
2018-04-16 01:59:09 +00:00
|
|
|
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
|
|
xhttp.overrideMimeType('application/xml'); // Force return to be XML
|
|
|
|
xhttp.send(path); // Start the process
|
|
|
|
|
|
|
|
// Use a cookie for persistence during browser session....
|
2018-04-22 06:03:43 +00:00
|
|
|
document.cookie = path + "; expires=Sun, 31 Dec 2034 12:00:00 UTC";
|
2018-04-16 01:59:09 +00:00
|
|
|
}
|