filer.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>SeaweedFS Filer</title>
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <link rel="stylesheet" href="/seaweedfsstatic/bootstrap/3.3.1/css/bootstrap.min.css">
  7. <style>
  8. body {
  9. padding-bottom: 128px;
  10. }
  11. #drop-area {
  12. border: 1px transparent;
  13. }
  14. #drop-area.highlight {
  15. border-color: purple;
  16. border: 2px dashed #ccc;
  17. }
  18. .button {
  19. display: inline-block;
  20. padding: 2px;
  21. background: #ccc;
  22. cursor: pointer;
  23. border-radius: 2px;
  24. border: 1px solid #ccc;
  25. float: right;
  26. }
  27. .button:hover {
  28. background: #ddd;
  29. }
  30. #fileElem {
  31. display: none;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <div class="container">
  37. <div class="page-header">
  38. <h1>
  39. <a href="https://github.com/chrislusf/seaweedfs"><img src="/seaweedfsstatic/seaweed50x50.png"></img></a>
  40. SeaweedFS Filer
  41. </h1>
  42. </div>
  43. <div class="row">
  44. <div>
  45. {{ range $entry := .Breadcrumbs }}
  46. <a href="{{ printpath $entry.Link }}">
  47. {{ $entry.Name }}
  48. </a>
  49. {{ end }}
  50. <label class="button" for="fileElem">Upload</label>
  51. </div>
  52. </div>
  53. <div class="row" id="drop-area">
  54. <form class="upload-form">
  55. <input type="file" id="fileElem" multiple onchange="handleFiles(this.files)">
  56. <table width="90%">
  57. {{$path := .Path }}
  58. {{ range $entry_index, $entry := .Entries }}
  59. <tr>
  60. <td>
  61. {{if $entry.IsDirectory}}
  62. <img src="/seaweedfsstatic/images/folder.gif" width="20" height="23">
  63. <a href="{{ printpath $path "/" $entry.Name "/"}}" >
  64. {{ $entry.Name }}
  65. </a>
  66. {{else}}
  67. <a href="{{ printpath $path "/" $entry.Name }}" >
  68. {{ $entry.Name }}
  69. </a>
  70. {{end}}
  71. </td>
  72. <td align="right" nowrap>
  73. {{if $entry.IsDirectory}}
  74. {{else}}
  75. {{ $entry.Mime }}&nbsp;
  76. {{end}}
  77. </td>
  78. <td align="right" nowrap>
  79. {{if $entry.IsDirectory}}
  80. {{else}}
  81. {{ $entry.Size | humanizeBytes }}&nbsp;
  82. {{end}}
  83. </td>
  84. <td nowrap>
  85. {{ $entry.Timestamp.Format "2006-01-02 15:04" }}
  86. </td>
  87. </tr>
  88. {{ end }}
  89. </table>
  90. </form>
  91. </div>
  92. {{if .ShouldDisplayLoadMore}}
  93. <div class="row">
  94. <a href={{ print .Path "?limit=" .Limit "&lastFileName=" .LastFileName}} >
  95. Load more
  96. </a>
  97. </div>
  98. {{end}}
  99. <br/>
  100. <br/>
  101. </div>
  102. </body>
  103. <script type="text/javascript">
  104. // ************************ Drag and drop ***************** //
  105. let dropArea = document.getElementById("drop-area")
  106. // Prevent default drag behaviors
  107. ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
  108. dropArea.addEventListener(eventName, preventDefaults, false)
  109. document.body.addEventListener(eventName, preventDefaults, false)
  110. })
  111. // Highlight drop area when item is dragged over it
  112. ;['dragenter', 'dragover'].forEach(eventName => {
  113. dropArea.addEventListener(eventName, highlight, false)
  114. })
  115. ;['dragleave', 'drop'].forEach(eventName => {
  116. dropArea.addEventListener(eventName, unhighlight, false)
  117. })
  118. // Handle dropped files
  119. dropArea.addEventListener('drop', handleDrop, false)
  120. function preventDefaults(e) {
  121. e.preventDefault()
  122. e.stopPropagation()
  123. }
  124. function highlight(e) {
  125. dropArea.classList.add('highlight')
  126. }
  127. function unhighlight(e) {
  128. dropArea.classList.remove('highlight')
  129. }
  130. function handleDrop(e) {
  131. var dt = e.dataTransfer
  132. var files = dt.files
  133. handleFiles(files)
  134. }
  135. function handleFiles(files) {
  136. files = [...files]
  137. files.forEach(uploadFile)
  138. window.location.reload()
  139. }
  140. function uploadFile(file, i) {
  141. var url = window.location.href
  142. var xhr = new XMLHttpRequest()
  143. var formData = new FormData()
  144. xhr.open('POST', url, false)
  145. formData.append('file', file)
  146. xhr.send(formData)
  147. }
  148. </script>
  149. </html>