index.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <style>
  4. #myProgress {
  5. width: 100%;
  6. background-color: #ddd;
  7. }
  8. #myBar {
  9. width: 1%;
  10. height: 30px;
  11. background-color: #4CAF50;
  12. }
  13. </style>
  14. <head>
  15. <meta charset="utf-8">
  16. <title>Transloadr</title>
  17. <script src="js/vue.js"></script>
  18. <script src="js/moment.js"></script>
  19. </head>
  20. <body>
  21. <div id="app">
  22. <input v-model="from" placeholder="from">
  23. <input v-model="to" placeholder="to">
  24. <button @click="send">Send</button>
  25. <table>
  26. <template v-for="(item, index) in transfers">
  27. <tr>
  28. <td> {{ item.id }}</td>
  29. <td style="width:200px;">
  30. <div id="myProgress">
  31. <div id="myBar" :style="{width: item.progress + '%'}">{{ item.progress }}</div>
  32. </div>
  33. </td>
  34. <td style="width:200px;">
  35. <pre></pre>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td> <button @click="cancel(item.id)">cancel</button>
  40. </td>
  41. <td>
  42. <pre>id: {{ item.id}}
  43. from: {{ item.from}}
  44. to: {{ item.to}}
  45. bytesRead: {{ item.bytesRead}}
  46. uploadError: {{ item.uploadError}}
  47. uploadCode: {{ item.uploadCode}}
  48. uploadResponseBody: {{ item.uploadResponseBody}}
  49. uploadDone: {{ item.uploadDone}}
  50. downloadDone: {{ item.downloadDone}}
  51. rate: {{ item.rate}}k/s
  52. </pre>
  53. </td>
  54. <td></td>
  55. </tr>
  56. </template>
  57. </table>
  58. </div>
  59. <script type="application/javascript">
  60. new Vue({
  61. el: '#app',
  62. data: {
  63. input: '',
  64. transfers: [],
  65. from: '',
  66. to: ''
  67. },
  68. created: function () {
  69. setInterval(this.update, 330);
  70. },
  71. watch: {},
  72. methods: {
  73. send: function (ts) {
  74. let data = new URLSearchParams();
  75. data.append('from', this.from);
  76. data.append('to', this.to);
  77. fetch('/xfer', {
  78. method: "POST",
  79. body: data
  80. }).then(response => {
  81. console.log(response);
  82. })
  83. .catch(error => {
  84. this.$data.log = [];
  85. console.log(error)
  86. });
  87. },
  88. cancel: function (id) {
  89. let data = new URLSearchParams();
  90. data.append('id', id);
  91. fetch('/cancel', {
  92. method: "POST",
  93. body: data
  94. }).then(response => {
  95. console.log(response);
  96. })
  97. .catch(error => {
  98. this.$data.log = [];
  99. console.log(error)
  100. });
  101. },
  102. ts2txt: function (ts) {
  103. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  104. },
  105. handleErrors: function (response) {
  106. if (!response.ok) throw Error(response.statusText);
  107. return response;
  108. },
  109. update: function (event) {
  110. fetch('/status', {method: "GET"})
  111. .then(this.handleErrors)
  112. .then(response => {
  113. return response.json();
  114. })
  115. .then(myJson => {
  116. this.$data.transfers = myJson;
  117. })
  118. .catch(error => {
  119. this.$data.log = [];
  120. console.log(error)
  121. });
  122. }
  123. }
  124. })
  125. </script>
  126. </body>
  127. </html>