index.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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>Transceivr</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" size="80"><br>
  23. <input v-model="to" placeholder="to" size="80"><br>
  24. <select v-model="toMethod">
  25. <option value="POST">POST</option>
  26. <option value="PUT">PUT</option>
  27. </select>
  28. <button @click="send">Send</button>
  29. <a href="#" @click="example1">example1</a>
  30. <a href="#" @click="example2">example2</a>
  31. <table>
  32. <template v-for="(item, index) in transfers">
  33. <tr>
  34. <td> {{ item.id }}</td>
  35. <td style="width:200px;" colspan="2">
  36. <div id="myProgress">
  37. <div id="myBar" :style="{width: item.progress + '%'}">{{ item.progress }}</div>
  38. </div>
  39. </td>
  40. <td style="width:200px;">
  41. <pre></pre>
  42. </td>
  43. </tr>
  44. <tr>
  45. <td><button @click="cancel(item.id)">cancel</button>
  46. </td><td>
  47. <pre>id: {{ item.id}}
  48. from: {{ item.from}}
  49. to: {{ item.to}}
  50. contentLength: {{ item.contentLength }}
  51. bytesRead: {{ item.bytesRead}}
  52. downloadError: {{ item.downloadError}}
  53. downloadCode: {{ item.downloadCode}}
  54. downloadDone: {{ item.downloadDone}}
  55. finished: {{ item.finished}}
  56. finishedAT: {{ item.finishedAT}}
  57. </pre>
  58. </td>
  59. <td><pre>rate: {{ item.rate}}k/s
  60. toMethod: {{ item.toMethod}}
  61. uploadError: {{ item.uploadError}}
  62. uploadCode: {{ item.uploadCode}}
  63. uploadResponseBody: {{ item.uploadResponseBody}}
  64. uploadDone: {{ item.uploadDone}}
  65. cpeeCallbackResult: {{ item.cpeeCallbackResult}}
  66. cpeeCallbackCode: {{ item.cpeeCallbackCode}}
  67. cpeeCallbackMessage: {{ item.cpeeCallbackMessage}}
  68. cpeeCallbackError: {{ item.cpeeCallbackError}}
  69. </pre></td>
  70. </tr>
  71. </template>
  72. </table>
  73. </div>
  74. <script type="application/javascript">
  75. new Vue({
  76. el: '#app',
  77. data: {
  78. input: '',
  79. transfers: [],
  80. from: '',
  81. to: '',
  82. toMethod: 'POST'
  83. },
  84. created: function () {
  85. setInterval(this.update, 330);
  86. },
  87. watch: {},
  88. methods: {
  89. example1: function () {
  90. this.$data.from='http://localhost:8082/zero?length=1000000';
  91. this.$data.to='http://localhost:8082/null';
  92. },
  93. example2: function () {
  94. this.$data.from='http://ftp.debian.org/debian/ls-lR.gz';
  95. this.$data.to='http://localhost:8082/null';
  96. },
  97. send: function (ts) {
  98. let data = new URLSearchParams();
  99. data.append('from', this.from);
  100. data.append('to', this.to);
  101. data.append('toMethod', this.toMethod);
  102. fetch('/xfer', {
  103. method: "POST",
  104. body: data
  105. }).then(response => {
  106. console.log(response);
  107. })
  108. .catch(error => {
  109. this.$data.log = [];
  110. console.log(error)
  111. });
  112. },
  113. cancel: function (id) {
  114. let data = new URLSearchParams();
  115. data.append('id', id);
  116. fetch('/cancel', {
  117. method: "POST",
  118. body: data
  119. }).then(response => {
  120. console.log(response);
  121. })
  122. .catch(error => {
  123. this.$data.log = [];
  124. console.log(error)
  125. });
  126. },
  127. ts2txt: function (ts) {
  128. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  129. },
  130. handleErrors: function (response) {
  131. if (!response.ok) throw Error(response.statusText);
  132. return response;
  133. },
  134. update: function (event) {
  135. fetch('/status', {method: "GET"})
  136. .then(this.handleErrors)
  137. .then(response => {
  138. return response.json();
  139. })
  140. .then(myJson => {
  141. this.$data.transfers = myJson;
  142. })
  143. .catch(error => {
  144. this.$data.log = [];
  145. console.log(error)
  146. });
  147. }
  148. }
  149. })
  150. </script>
  151. </body>
  152. </html>