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.

182 lines
5.0 KiB

  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. .qrImage {
  34. display: block;
  35. margin-left: auto;
  36. margin-right: auto;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div class="container">
  42. <div class="page-header">
  43. <h1>
  44. <a href="https://github.com/chrislusf/seaweedfs"><img src="/seaweedfsstatic/seaweed50x50.png"></img></a>
  45. SeaweedFS Filer
  46. </h1>
  47. </div>
  48. <div class="row">
  49. <div>
  50. {{ range $entry := .Breadcrumbs }}
  51. <a href="{{ printpath $entry.Link }}">
  52. {{ $entry.Name }}
  53. </a>
  54. {{ end }}
  55. <label class="button" for="fileElem">Upload</label>
  56. </div>
  57. </div>
  58. <div class="row" id="drop-area">
  59. <form class="upload-form">
  60. <input type="file" id="fileElem" multiple onchange="handleFiles(this.files)">
  61. <table width="90%">
  62. {{$path := .Path }}
  63. {{ range $entry_index, $entry := .Entries }}
  64. <tr>
  65. <td>
  66. {{if $entry.IsDirectory}}
  67. <img src="/seaweedfsstatic/images/folder.gif" width="20" height="23">
  68. <a href="{{ printpath $path "/" $entry.Name "/"}}" >
  69. {{ $entry.Name }}
  70. </a>
  71. {{else}}
  72. <a href="{{ printpath $path "/" $entry.Name }}" >
  73. {{ $entry.Name }}
  74. </a>
  75. {{end}}
  76. </td>
  77. <td align="right" nowrap>
  78. {{if $entry.IsDirectory}}
  79. {{else}}
  80. {{ $entry.Mime }}&nbsp;
  81. {{end}}
  82. </td>
  83. <td align="right" nowrap>
  84. {{if $entry.IsDirectory}}
  85. {{else}}
  86. {{ $entry.Size | humanizeBytes }}&nbsp;
  87. {{end}}
  88. </td>
  89. <td nowrap>
  90. {{ $entry.Timestamp.Format "2006-01-02 15:04" }}
  91. </td>
  92. </tr>
  93. {{ end }}
  94. </table>
  95. </form>
  96. </div>
  97. {{if .ShouldDisplayLoadMore}}
  98. <div class="row">
  99. <a href={{ print .Path "?limit=" .Limit "&lastFileName=" .LastFileName}} >
  100. Load more
  101. </a>
  102. </div>
  103. {{end}}
  104. <br/>
  105. <br/>
  106. <div class="navbar navbar-fixed-bottom">
  107. <img src="data:image/png;base64,{{.QrImage}}" class="qrImage"/>
  108. </div>
  109. </div>
  110. </body>
  111. <script type="text/javascript">
  112. // ************************ Drag and drop ***************** //
  113. let dropArea = document.getElementById("drop-area")
  114. // Prevent default drag behaviors
  115. ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
  116. dropArea.addEventListener(eventName, preventDefaults, false)
  117. document.body.addEventListener(eventName, preventDefaults, false)
  118. })
  119. // Highlight drop area when item is dragged over it
  120. ;['dragenter', 'dragover'].forEach(eventName => {
  121. dropArea.addEventListener(eventName, highlight, false)
  122. })
  123. ;['dragleave', 'drop'].forEach(eventName => {
  124. dropArea.addEventListener(eventName, unhighlight, false)
  125. })
  126. // Handle dropped files
  127. dropArea.addEventListener('drop', handleDrop, false)
  128. function preventDefaults(e) {
  129. e.preventDefault()
  130. e.stopPropagation()
  131. }
  132. function highlight(e) {
  133. dropArea.classList.add('highlight')
  134. }
  135. function unhighlight(e) {
  136. dropArea.classList.remove('highlight')
  137. }
  138. function handleDrop(e) {
  139. var dt = e.dataTransfer
  140. var files = dt.files
  141. handleFiles(files)
  142. }
  143. function handleFiles(files) {
  144. files = [...files]
  145. files.forEach(uploadFile)
  146. window.location.reload()
  147. }
  148. function uploadFile(file, i) {
  149. var url = window.location.href
  150. var xhr = new XMLHttpRequest()
  151. var formData = new FormData()
  152. xhr.open('POST', url, false)
  153. formData.append('file', file)
  154. xhr.send(formData)
  155. }
  156. </script>
  157. </html>