(folders)
| 286 | }); |
| 287 | } |
| 288 | function 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);'>← ..</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 + "')\">📁</span> " + |
| 322 | "<span style='cursor:pointer' onclick=\"renameFile('" + item.path + "', '" + item.name + "')\">✏</span> " + |
| 323 | "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'delete')\">🗑</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)'>⋮</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 ? " <span style='cursor:pointer' onclick=\"startUpdate('" + item.path + "')\">🚀</span>" : ""); |
| 332 | const ac = (isEditable(item.name) ? "<span style='cursor:pointer' onclick=\"editFile('" + item.path + "')\">✎</span> " : "") + |
| 333 | "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'download')\">⬇</span> " + |
| 334 | "<span style='cursor:pointer' onclick=\"renameFile('" + item.path + "', '" + item.name + "')\">✏</span> " + |
| 335 | "<span style='cursor:pointer' onclick=\"downloadDeleteButton('" + item.path + "', 'delete')\">🗑</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)'>⋮</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> " + ac + "</td></tr>\n"; |
| 340 | }); |
| 341 | tableContent += "</table>"; |
| 342 | _("details").innerHTML = tableContent; |
| 343 | } else { |
| 344 | console.error("Request Error: " + xhr.status); |
| 345 | } |
no test coverage detected