index.html 5.9 KB

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