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 2.0KB

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