index.html 5.0 KB

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