MCPcopy Create free account
hub / github.com/bmorcelli/Launcher / listFilesButton

Function listFilesButton

webUi/scripts.js:288–366  ·  view source on GitHub ↗
(folders)

Source from the content-addressed store, hash-verified

286 });
287}
288function listFilesButton(folders) {
289 _("drop-area").style.display = 'block';
290 _("actualFolder").value = folders;
291 let previousFolder = folders.substring(0, folders.lastIndexOf('/'));
292 if (previousFolder === "") { previousFolder = "/"; }
293 httpRequest("GET", "/listfiles?folder=" + folders, {
294 onload: (xhr) => {
295 if (xhr.status === 200) {
296 const responseText = xhr.responseText;
297 const lines = responseText.split('\n');
298 let tableContent = "<table><tr><th>Name</th><th class='sz'>Size</th><th class='ac'></th><th class='mb'></th></tr>\n";
299 tableContent += "<tr><td colspan='4'><a onclick=\"listFilesButton('" + previousFolder + "')\" href='javascript:void(0);'>&#8592; ..</a></td></tr>\n";
300 let folder = "";
301 const foldersArray = [];
302 const filesArray = [];
303 lines.forEach((line) => {
304 if (line) {
305 const type = line.substring(0, 2);
306 const path = line.substring(3, line.lastIndexOf(':'));
307 const filename = line.substring(3, line.lastIndexOf(':'));
308 const size = line.substring(line.lastIndexOf(':') + 1);
309 if (type === "pa") {
310 if (path !== "" && folder !== "/") folder = path + (path.endsWith("/") ? "" : "/");
311 } else if (type === "Fo") {
312 foldersArray.push({ path: folder + path, name: filename });
313 } else if (type === "Fi") {
314 filesArray.push({ path: folder + path, name: filename, size });
315 }
316 }
317 });
318 foldersArray.sort((a, b) => a.name.localeCompare(b.name));
319 filesArray.sort((a, b) => a.name.localeCompare(b.name));
320 foldersArray.forEach((item) => {
321 const ac = "<span style='cursor:pointer;color:#e0d204' onclick=\"listFilesButton('" + item.path + "')\">&#128193;</span>&nbsp" +
322 "<span style='cursor:pointer' onclick=\"renameFile('" + item.path + "', '" + item.name + "')\">&#9999;</span>&nbsp" +
323 "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'delete')\">&#128465;</span>";
324 tableContent += "<tr><td><a onclick=\"listFilesButton('" + item.path + "')\" href='javascript:void(0);'>" + item.name + "</a></td>" +
325 "<td class='sz'></td><td class='ac'>" + ac + "</td>" +
326 "<td class='mb'><button onclick='toggleRow(this)'>&#8942;</button></td></tr>\n" +
327 "<tr class='mrow' style='display:none'><td colspan='4'>" + ac + "</td></tr>\n";
328 });
329 filesArray.forEach((item) => {
330 const isBin = item.name.split('.').pop().toLowerCase() === "bin";
331 const fname = item.name + (isBin ? "&nbsp<span style='cursor:pointer' onclick=\"startUpdate('" + item.path + "')\">&#128640;</span>" : "");
332 const ac = (isEditable(item.name) ? "<span style='cursor:pointer' onclick=\"editFile('" + item.path + "')\">&#9998;</span>&nbsp" : "") +
333 "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'download')\">&#11015;</span>&nbsp" +
334 "<span style='cursor:pointer' onclick=\"renameFile('" + item.path + "', '" + item.name + "')\">&#9999;</span>&nbsp" +
335 "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'delete')\">&#128465;</span>";
336 tableContent += "<tr><td>" + fname + "</td>" +
337 "<td class='sz'>" + item.size + "</td><td class='ac'>" + ac + "</td>" +
338 "<td class='mb'><button onclick='toggleRow(this)'>&#8942;</button></td></tr>\n" +
339 "<tr class='mrow' style='display:none'><td colspan='4'><span style='color:var(--dim);font-size:.75rem'>" + item.size + "</span>&nbsp;&nbsp;" + ac + "</td></tr>\n";
340 });
341 tableContent += "</table>";
342 _("details").innerHTML = tableContent;
343 } else {
344 console.error("Request Error: " + xhr.status);
345 }

Callers 4

renameFileFunction · 0.85
downloadDeleteButtonFunction · 0.85
scripts.jsFile · 0.85
processNextUploadFunction · 0.85

Calls 4

_Function · 0.85
httpRequestFunction · 0.85
isEditableFunction · 0.85
handleFileFormFunction · 0.85

Tested by

no test coverage detected