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.

171 lines
3.7 KiB

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