index.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. downloadError: {{ item.downloadError}}
  51. downloadCode: {{ item.downloadCode}}
  52. downloadDone: {{ item.downloadDone}}
  53. cpeeCallbackResult: {{ item.cpeeCallbackResult}}
  54. cpeeCallbackCode: {{ item.cpeeCallbackCode}}
  55. cpeeCallbackMessage: {{ item.cpeeCallbackMessage}}
  56. cpeeCallbackError: {{ item.cpeeCallbackError}}
  57. rate: {{ item.rate}}k/s
  58. </pre>
  59. </td>
  60. <td></td>
  61. </tr>
  62. </template>
  63. </table>
  64. </div>
  65. <script type="application/javascript">
  66. new Vue({
  67. el: '#app',
  68. data: {
  69. input: '',
  70. transfers: [],
  71. from: '',
  72. to: ''
  73. },
  74. created: function () {
  75. setInterval(this.update, 330);
  76. },
  77. watch: {},
  78. methods: {
  79. send: function (ts) {
  80. let data = new URLSearchParams();
  81. data.append('from', this.from);
  82. data.append('to', this.to);
  83. fetch('/xfer', {
  84. method: "POST",
  85. body: data
  86. }).then(response => {
  87. console.log(response);
  88. })
  89. .catch(error => {
  90. this.$data.log = [];
  91. console.log(error)
  92. });
  93. },
  94. cancel: function (id) {
  95. let data = new URLSearchParams();
  96. data.append('id', id);
  97. fetch('/cancel', {
  98. method: "POST",
  99. body: data
  100. }).then(response => {
  101. console.log(response);
  102. })
  103. .catch(error => {
  104. this.$data.log = [];
  105. console.log(error)
  106. });
  107. },
  108. ts2txt: function (ts) {
  109. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  110. },
  111. handleErrors: function (response) {
  112. if (!response.ok) throw Error(response.statusText);
  113. return response;
  114. },
  115. update: function (event) {
  116. fetch('/status', {method: "GET"})
  117. .then(this.handleErrors)
  118. .then(response => {
  119. return response.json();
  120. })
  121. .then(myJson => {
  122. this.$data.transfers = myJson;
  123. })
  124. .catch(error => {
  125. this.$data.log = [];
  126. console.log(error)
  127. });
  128. }
  129. }
  130. })
  131. </script>
  132. </body>
  133. </html>