2
0

container_file.htm 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <div id="upload-container" class="cbi-value cbi-value-last">
  2. <label class="cbi-value-title" for="archive"><%:Upload%></label>
  3. <div class="cbi-value-field">
  4. <input type="file" name="upload_archive" accept="application/x-tar" id="upload_archive" />
  5. </div>
  6. <br />
  7. <label class="cbi-value-title" for="path"><%:Path%></label>
  8. <div class="cbi-value-field">
  9. <input type="text" class="cbi-input-text" name="path" value="/tmp/" id="path" />
  10. </div>
  11. <br />
  12. <div class="cbi-value-field">
  13. <input type="button"" class="btn cbi-button cbi-button-action important" id="upload" name="upload" value="<%:Upload%>" />
  14. <input type="button"" class="btn cbi-button cbi-button-action important" id="download" name="download" value="<%:Download%>" />
  15. </div>
  16. </div>
  17. <script>
  18. let btnUpload = document.getElementById('upload')
  19. btnUpload.onclick = function (e) {
  20. let uploadArchive = document.getElementById('upload_archive')
  21. let uploadPath = document.getElementById('path').value
  22. if (!uploadArchive.value || !uploadPath) {
  23. docker_status_message('warning', "<%:Please input the PATH and select the file !%>")
  24. document.getElementById('docker_apply_overlay').addEventListener(
  25. "click",
  26. (e)=>{
  27. docker_status_message()
  28. }
  29. )
  30. return
  31. }
  32. let fileName = uploadArchive.files[0].name
  33. let formData = new FormData()
  34. formData.append('upload-filename', fileName)
  35. formData.append('upload-path', uploadPath)
  36. formData.append('upload-archive', uploadArchive.files[0])
  37. let xhr = new XMLHttpRequest()
  38. xhr.open("POST", '<%=luci.dispatcher.build_url("admin/docker/container_put_archive")%>/<%=self.container%>', true)
  39. xhr.onload = function() {
  40. if (xhr.status == 200) {
  41. uploadArchive.value = ''
  42. docker_status_message('notice', "<%:Upload Success%>")
  43. }
  44. else {
  45. docker_status_message('warning', "<%:Upload Error%>:" + xhr.statusText)
  46. }
  47. document.getElementById('docker_apply_overlay').addEventListener(
  48. "click",
  49. (e)=>{
  50. docker_status_message()
  51. }
  52. )
  53. }
  54. xhr.send(formData)
  55. }
  56. let btnDownload = document.getElementById('download')
  57. btnDownload.onclick = function (e) {
  58. let downloadPath = document.getElementById('path').value
  59. if (!downloadPath) {
  60. docker_status_message('warning', "<%:Please input the PATH !%>")
  61. document.getElementById('docker_apply_overlay').addEventListener(
  62. "click",
  63. (e)=>{
  64. docker_status_message()
  65. }
  66. )
  67. return
  68. }
  69. window.open('<%=luci.dispatcher.build_url("admin/docker/container_get_archive")%>?id=<%=self.container%>&path=' + encodeURIComponent(downloadPath))
  70. }
  71. </script>