share.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>File Share | WebStick</title>
  7. <link rel="icon" type="image/png" href="/favicon.png" />
  8. <script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.js" integrity="sha512-gnoBksrDbaMnlE0rhhkcx3iwzvgBGz6mOEj4/Y5ZY09n55dYddx6+WYc72A55qEesV8VX2iMomteIwobeGK1BQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  11. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.3/semantic.min.css" integrity="sha512-3quBdRGJyLy79hzhDDcBzANW+mVqPctrGCfIPosHQtMKb3rKsCxfyslzwlz2wj1dT8A7UX+sEvDjaUv+WExQrA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  12. <link rel="preconnect" href="https://fonts.googleapis.com">
  13. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  14. <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@100;200&display=swap" rel="stylesheet">
  15. <style>
  16. body {
  17. }
  18. .main{
  19. display: flex;
  20. align-items: center;
  21. justify-content: center;
  22. height: calc(100vh - 60px);
  23. margin: 0;
  24. }
  25. #qr-code {
  26. max-width: 300px;
  27. height: 300px;
  28. }
  29. #generate-btn {
  30. cursor: pointer;
  31. }
  32. .ui.header,button,input{
  33. font-family: 'Noto Sans TC', sans-serif !important;
  34. }
  35. @media screen and (min-width: 768px) {
  36. #title{
  37. padding-top: 3em;
  38. border-right: 1px solid #dedede;
  39. padding-right: 5em;
  40. }
  41. #title .ui.header{
  42. width: 300px;
  43. }
  44. #qrgrid{
  45. padding-left: 5em;
  46. }
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div class="main">
  52. <div class="ui stackable grid">
  53. <div id="title" class="eight wide column" align="center">
  54. <h2 class="ui header">
  55. <span id="filename"><i class="ui loading spinner icon"></i> Loading</span>
  56. <div class="sub header" id="filepath"></div>
  57. </h2>
  58. <table class="ui very basic collapsing celled table">
  59. <tbody>
  60. <tr>
  61. <td>File Size</td>
  62. <td id="filesize"></td>
  63. </tr>
  64. <tr>
  65. <td>Share ID</td>
  66. <td id="shareid"></td>
  67. </tr>
  68. </tbody>
  69. </table>
  70. <a class="ui basic button" id="downloadBtn" href="" target="_blank" download=""><i class="ui blue download icon"></i> Download</a>
  71. </div>
  72. <div id="qrgrid" class="eight wide column" align="center">
  73. <div style="width: 300px">
  74. <div id="qr-code"></div>
  75. <Br>
  76. <p>Download on another device</p>
  77. </div>
  78. </div>
  79. </div>
  80. <script>
  81. function initDownloadInfo(){
  82. const urlParams = new URLSearchParams(window.location.search);
  83. const id = urlParams.get('id');
  84. $.get("/share?id=" + id + "&prop", function(data){
  85. if (data.error == undefined){
  86. $("#filename").text(data.filename);
  87. $("#filepath").text(data.filepath);
  88. $("#filesize").text(humanFileSize(data.filesize, false, 2));
  89. $("#shareid").text(data.shareid);
  90. $("#downloadBtn").attr("href", "/share?id=" + id + "&download");
  91. $("#downloadBtn").attr("download", data.filename);
  92. document.title = data.filename + " | WebStick Share"
  93. }
  94. })
  95. }
  96. initDownloadInfo();
  97. function initQrCode(url){
  98. var qrcode = new QRCode(document.getElementById('qr-code'), {
  99. text: url,
  100. width: 300,
  101. height: 300
  102. });
  103. }
  104. initQrCode(window.location.href);
  105. function humanFileSize(bytes, si=false, dp=1) {
  106. const thresh = si ? 1000 : 1024;
  107. if (Math.abs(bytes) < thresh) {
  108. return bytes + ' B';
  109. }
  110. const units = si
  111. ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
  112. : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
  113. let u = -1;
  114. const r = 10**dp;
  115. do {
  116. bytes /= thresh;
  117. ++u;
  118. } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
  119. return bytes.toFixed(dp) + ' ' + units[u];
  120. }
  121. </script>
  122. </body>
  123. </html>