You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

files.html 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Mediator - Files</title>
  6. <link rel="stylesheet" href="style.css">
  7. <link rel="icon" type="image/png" href="favicon.png">
  8. <style>
  9. #breadcrumbs .crumb:first-child {
  10. margin-left: 0px;
  11. }
  12. #breadcrumbs .crumb {
  13. margin-left: 2px;
  14. margin-right: 2px;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div id="breadcrumbs"></div>
  20. <ul id="files"></ul>
  21. <script src="util.js"></script>
  22. <script>
  23. let breadcrumbsEl = document.getElementById("breadcrumbs");
  24. let filesEl = document.getElementById("files");
  25. function renderEntry(path, ent) {
  26. if (ent.type == "d") {
  27. let href =
  28. path == "/" ? "#/" + ent.name
  29. : "#" + path + "/" + ent.name;
  30. return html("li", {}, [
  31. html("a", {href}, ent.name + "/"),
  32. ]);
  33. } else {
  34. let href =
  35. path == "/" ? "play.html#/" + ent.name
  36. : "play.html#" + path + "/" + ent.name;
  37. return html("li", {}, [
  38. html("a", {href}, ent.name),
  39. ]);
  40. }
  41. }
  42. function renderEntries(path, entries) {
  43. let els = entries.map(ent => renderEntry(path, ent));
  44. if (entries.length == 0) {
  45. els.push(html("li", {}, "No files."));
  46. }
  47. return els;
  48. }
  49. function renderBreadcrumbs(path) {
  50. let crumbPath = "#/";
  51. let els = [];
  52. els.push(html("a",
  53. {class: "crumb", href: "#/"}, "/"));
  54. for (let component of path.split("/")) {
  55. if (component == "") {
  56. continue;
  57. }
  58. if (crumbPath == "#/") {
  59. crumbPath += component;
  60. } else {
  61. crumbPath += "/" + component;
  62. els.push(html("text", "/"));
  63. }
  64. els.push(html("a",
  65. {class: "crumb", href: crumbPath}, component));
  66. }
  67. return els;
  68. }
  69. async function render() {
  70. let path = "/";
  71. if (location.hash.length > 1) {
  72. path = location.hash.substr(1);
  73. }
  74. let resp = await api("GET", "dir" + path);
  75. renderToElement(filesEl, renderEntries(path, resp.entries));
  76. renderToElement(breadcrumbsEl, renderBreadcrumbs(path));
  77. }
  78. render();
  79. window.addEventListener("hashchange", render);
  80. </script>
  81. </body>
  82. </html>