index.html 4.4 KB

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