index.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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>
  58. <button @click="cancel(item.id)">cancel</button>
  59. </td>
  60. <td>
  61. <pre>id: {{ item.id}}
  62. from: {{ item.from}}
  63. to: {{ item.to}}
  64. contentLength: {{ item.contentLength }}
  65. bytesRead: {{ item.bytesRead}}
  66. downloadError: {{ item.downloadError}}
  67. downloadCode: {{ item.downloadCode}}
  68. downloadDone: {{ item.downloadDone}}
  69. finished: {{ item.finished}}
  70. finishedAT: {{ item.finishedAT}}
  71. </pre>
  72. </td>
  73. <td><pre>rate: {{ item.rate}}k/s
  74. toMethod: {{ item.toMethod}}
  75. uploadError: {{ item.uploadError}}
  76. uploadCode: {{ item.uploadCode}}
  77. uploadResponseBody: {{ item.uploadResponseBody}}
  78. uploadDone: {{ item.uploadDone}}
  79. cpeeCallbackResult: {{ item.cpeeCallbackResult}}
  80. cpeeCallbackCode: {{ item.cpeeCallbackCode}}
  81. cpeeCallbackMessage: {{ item.cpeeCallbackMessage}}
  82. cpeeCallbackError: {{ item.cpeeCallbackError}}
  83. </pre>
  84. </td>
  85. </tr>
  86. </template>
  87. </table>
  88. </div>
  89. <script type="application/javascript">
  90. new Vue({
  91. el: '#app',
  92. data: {
  93. input: '',
  94. transfers: [],
  95. from: '',
  96. to: '',
  97. toMethod: 'POST',
  98. toMime: 'application/octet-stream',
  99. type: 'xfer',
  100. body: ''
  101. },
  102. created: function () {
  103. setInterval(this.update, 330);
  104. },
  105. watch: {},
  106. methods: {
  107. baseURL: function () {
  108. let url = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
  109. if (url.endsWith('/'))
  110. url = url.slice(0, -1);
  111. return url;
  112. },
  113. example1: function () {
  114. this.$data.from = this.baseURL() + '/zero?length=1000000';
  115. this.$data.to = this.baseURL() + '/null';
  116. this.$data.type = 'xfer';
  117. this.$data.toMethod = 'POST';
  118. this.$data.toMime = 'application/octet-stream';
  119. },
  120. example2: function () {
  121. this.$data.from = 'http://ftp.debian.org/debian/ls-lR.gz';
  122. this.$data.to = this.baseURL() + '/null';
  123. this.$data.type = 'xfer';
  124. this.$data.toMethod = 'POST';
  125. this.$data.toMime = 'application/octet-stream';
  126. },
  127. example3: function () {
  128. this.$data.body = '[{}]';
  129. this.$data.to = this.baseURL() + '/null';
  130. this.$data.toMethod = 'POST';
  131. this.$data.type = 'send';
  132. this.$data.toMime = 'application/json';
  133. },
  134. send: function (ts) {
  135. let data = new URLSearchParams();
  136. data.append('from', this.from);
  137. data.append('to', this.to);
  138. data.append('toMethod', this.toMethod);
  139. data.append('body', this.body);
  140. data.append('toMime', this.toMime);
  141. ep = this.$data.type;
  142. fetch(ep, {
  143. method: "POST",
  144. body: data
  145. }).then(response => {
  146. console.log(response);
  147. })
  148. .catch(error => {
  149. this.$data.log = [];
  150. console.log(error)
  151. });
  152. },
  153. cancel: function (id) {
  154. let data = new URLSearchParams();
  155. data.append('id', id);
  156. fetch('cancel', {
  157. method: "POST",
  158. body: data
  159. }).then(response => {
  160. console.log(response);
  161. })
  162. .catch(error => {
  163. this.$data.log = [];
  164. console.log(error)
  165. });
  166. },
  167. ts2txt: function (ts) {
  168. return moment(ts).format('YYYY-MM-DD hh:mm ss.SSS ')
  169. },
  170. handleErrors: function (response) {
  171. if (!response.ok) throw Error(response.statusText);
  172. return response;
  173. },
  174. update: function (event) {
  175. fetch('status', {method: "GET"})
  176. .then(this.handleErrors)
  177. .then(response => {
  178. return response.json();
  179. })
  180. .then(myJson => {
  181. this.$data.transfers = myJson;
  182. })
  183. .catch(error => {
  184. this.$data.log = [];
  185. console.log(error)
  186. });
  187. }
  188. }
  189. })
  190. </script>
  191. </body>
  192. </html>