Added web directory manager

+ Added web directory manager
+ Added dummy service expose proxy page
+ Moved ACME and renew to a new section in TLS management page
This commit is contained in:
Toby Chui
2023-09-24 23:44:48 +08:00
parent b63a0fc246
commit fd6ba56143
13 changed files with 782 additions and 188 deletions

View File

@ -78,10 +78,6 @@
<br>
</div>
<div id="propertiesView" class="small">
<div class="preview" style="margin-top: 0.4em;" align="center">
<img class="ui image" style="max-height: 300px;">
<audio src="" controls style="display:none; width: 100%;"></audio>
</div>
<h3 class="ui header" style="margin-top: 0.4em;">
<span class="filename" style="word-break: break-all;" locale="sidebar/default/nofileselected">No File Selected</span>
<div class="sub header vpath" style="word-break: break-all;" locale="sidebar/default/instruction">Select a file to view file properties</div>
@ -91,7 +87,6 @@
</tbody>
</table>
<button id="loadPreviewButton" class="ui small fluid basic disabled button" onclick="loadPreview();">Load Preview</button>
</div>
<div id="uploadProgressBar">
<div class="ui small indicating progress" style="margin-bottom: 0px !important; border-radius: 0 !important;">
@ -116,9 +111,7 @@
//File operations
let cutMode = false;
let cutPendingFilepath = [];
let copyBuffering = false;
let copySrcFilename = "";
let copyPendingFile = undefined;
let copyPendingFiles = [];
//History
let dirHistory = [];
@ -479,9 +472,9 @@
msgbox(data.error, false);
}else{
data.forEach(function(filedata){
let isDir = filedata.IsDir;
let filename = filedata.Filename;
let filesize = filedata.Filesize;
let isDir = filedata.isDir;
let filename = filedata.filename;
let filesize = filedata.size;
if (isDir){
$("#folderList").append(`<div class="fileObject item" draggable="true" filename="${filename}" filepath="${path + filename}" ondblclick="openthis(this,event);" type="folder">
<span style="display:inline-block !important;word-break: break-all; width:100%;" class="normal object">
@ -527,46 +520,7 @@
listDir(targetPath);
}else{
let ext = $(target).attr("filepath").split(".").pop();
if (ext == "txt" || ext == "md"){
//Open with markdown editor
let hash = encodeURIComponent(JSON.stringify({
"filename": $(target).attr("filename"),
"filepath": $(target).attr("filepath")
}))
window.open("mde/index.html#" + hash);
}else if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "webp"){
//Open with photo viewer
let hash = encodeURIComponent(JSON.stringify({
"filename": $(target).attr("filename"),
"filepath": $(target).attr("filepath")
}))
window.open("photo.html#" + hash);
}else if (ext == "mp3" || ext == "aac" || ext == "ogg"){
//Open with music player
let hash = encodeURIComponent(JSON.stringify({
"filename": $(target).attr("filename"),
"filepath": $(target).attr("filepath")
}))
window.open("music.html#" + hash);
}else if (ext == "mp4" || ext == "webm"){
//Open with video player
let hash = encodeURIComponent(JSON.stringify({
"filename": $(target).attr("filename"),
"filepath": $(target).attr("filepath")
}))
window.open("video.html#" + hash);
}else if (isCodeFiles(ext)){
//Open with notepad
//**Notes the array wrapper in JSON object**
let hash = encodeURIComponent(JSON.stringify([{
"filename": $(target).attr("filename"),
"filepath": $(target).attr("filepath")
}]))
window.open("notepad/index.html#" + hash);
}else{
window.open("/api/fs/download?file=" + $(target).attr("filepath") + "&preview=true");
}
window.open("/api/fs/download?file=" + $(target).attr("filepath") + "&preview=true");
}
}
@ -600,18 +554,6 @@
let ext = filenameOnly.pop();
filenameOnly = filenameOnly.join(".");
/*
//Skip checking as modern FAT32 file systems can store as LONG FILENAME
if (filenameOnly.length > 8){
msgbox("File name too long (8 char max)", false);
return;
}
if (ext.length > 3){
msgbox("File extension too long (3 char max)", false);
return
}
*/
//OK! Create the file
const blob = new Blob(["\n"], { type: 'text/plain' });
@ -622,18 +564,13 @@
}
function newFolder(){
var folderName = window.prompt("Name for new folder (8 char max): ", "Folder");
var folderName = window.prompt("Name for new folder: ", "Folder");
if (folderName.indexOf("/") >= 0){
//Contains /. Reject
msgbox("Folder name cannot contain path seperator", false);
return;
}
if (folderName.length > 8){
msgbox("Folder name too long (8 char max)", false);
return;
}
$.post("/api/fs/newFolder?path=" + currentPath + folderName, function(data){
if (data.error != undefined){
msgbox(data.error, false);
@ -656,20 +593,12 @@
msgbox("File name cannot contain path seperator", false);
return;
}
/*
//FAT32 allows filename longer than 8.3
if (!isFilenameValid(newName)){
msgbox("File name too long (8 char max)", false);
return;
}
*/
if (newName && newName != oldName) {
// User entered a new name, perform renaming logic here
console.log(oldPath, currentPath + newName);
$.ajax({
url: "/api/fs/move?src=" + oldPath + "&dest=" + currentPath + newName,
url: "/api/fs/move?srcpath=" + oldPath + "&destpath=" + currentPath + newName,
method: "POST",
success: function(data){
if (data.error != undefined){
@ -729,7 +658,7 @@
File Size
</td>
<td>
${bytesToSize(data.filesize)}
${bytesToSize(data.size)}
</td>
</tr><tr>
<td style="${styleOverwrite}">
@ -764,19 +693,6 @@
</td>
</tr>`);
//Folder is not previewable
$("#propertiesView").find(".preview").find("img").attr("xsrc", "");
$("#loadPreviewButton").addClass("disabled");
}else{
let ext = data.filepath.split(".").pop();
if (isPreviewable("." + ext)){
$("#propertiesView").find(".preview").find("img").attr("xsrc", "/api/fs/download?preview=true&file=" + data.filepath);
$("#loadPreviewButton").removeClass("disabled");
}else{
$("#propertiesView").find(".preview").find("img").attr("xsrc", "");
$("#loadPreviewButton").addClass("disabled");
}
}
})
}
@ -825,7 +741,7 @@
}
}
function humanFileSize(bytes, si=false, dp=1) {
function humanFileSize(bytes, si=true, dp=1) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
@ -888,7 +804,7 @@
$("#pasteButton").addClass("disabled");
console.log('Selected file:', file);
var formdata = new FormData();
formdata.append("file1", file);
formdata.append("file", file);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", function(event){
@ -909,7 +825,7 @@
}, false); // doesnt appear to ever get called even upon success
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
ajax.open("POST", "/upload?dir=" + dir);
ajax.open("POST", "/api/fs/upload?dir=" + dir);
ajax.send(formdata);
}
@ -961,48 +877,23 @@
//Copy file
function copy(){
//TODO: Add copy API
if ($(".fileObject.selected").length == 0){
//No file selected
msgbox("No file selected", false);
return;
}
if ($(".fileObject.selected").length > 1){
msgbox("WebStick can only support 1 file copy at a time", false);
return;
}
if ($(".fileObject.selected").attr('type') == "folder"){
msgbox("Folder copy is not supported", false);
return;
}
let url = "/api/fs/download?file=" + $(".fileObject.selected").attr("filepath");
let filename = $(".fileObject.selected").attr("filename");
cutMode = false;
copyBuffering = true;
copySrcFilename = filename;
console.log("Buffering " + filename + " from " + url);
msgbox("Allocating memory for copy...")
$("#pasteButton").addClass("disabled");
$("#copyButton").addClass("disabled");
// Fetch the content from the URL
fetch(url).then(response => response.blob()).then(blob => {
// Create a new File object from the Blob
copyPendingFile = (blob);
msgbox("File Ready to Paste");
$("#pasteButton").removeClass("disabled");
$("#copyButton").removeClass("disabled");
copyBuffering = false;
}).catch(error => {
msgbox("Copy Allocation Failed", false);
$("#pasteButton").removeClass("disabled");
$("#copyButton").removeClass("disabled");
copyBuffering = false;
let selectedFiles = [];
$(".fileObject.selected").each(function(){
let filepath = $(this).attr("filepath");
selectedFiles.push(filepath);
console.log(filepath);
});
copyPendingFiles = selectedFiles;
cutMode = false;
msgbox(`${selectedFiles.length} files ready to paste`, true)
}
function fileExistsInThisFolder(filename){
@ -1024,7 +915,7 @@
let filepath = fileToPaste.filepath;
$.ajax({
url: "/api/fs/move?src=" + filepath + "&dest=" + currentPath + filename,
url: "/api/fs/move?srcpath=" + filepath + "&destpath=" + currentPath + filename,
method: "POST",
success: function(data){
if (data.error != undefined){
@ -1041,32 +932,42 @@
});
}else{
//Copy and Paste
if (copyBuffering){
msgbox("Copy buffer allocation in progress", false);
return;
}
let pasteFilename = copySrcFilename;
let counter = 1;
while(fileExistsInThisFolder(pasteFilename)){
let nameOnly = copySrcFilename.split(".");
let ext = nameOnly.pop();
nameOnly = nameOnly.join(".");
pasteFilename = nameOnly + "-" + counter + "." + ext;
counter++;
}
//Change the name if there is name clash
const file = new File([copyPendingFile], pasteFilename);
//Upload the file
msgbox("Writing file to SD card...");
handleFile(file, currentPath, function(){
msgbox("File Pasted");
});
copyFirstItemInQueueUntilAllCopied();
}
}
function copyFirstItemInQueueUntilAllCopied(){
let file = copyPendingFiles.shift();
let startingDir = currentPath;
$.ajax({
url: "/api/fs/copy",
method: "POST",
data: {
"srcpath": file,
"destpath": currentPath
},
success: function(data){
if (data.error != undefined){
msgbox(data.error, false);
}else{
if (copyPendingFiles.length > 0){
//Contine to copy and paste the files
copyFirstItemInQueueUntilAllCopied();
if (startingDir == currentPath){
refresh();
}
}else{
//All copy operation done
msgbox("Files copied");
if (startingDir == currentPath){
refresh();
}
}
}
}
})
}
function sortFileList(){
sortFileObjects("folderList");
sortFileObjects("fileList");