search.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Search Engine</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" >
  7. <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  8. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" />
  9. <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script>
  10. <style>
  11. body{
  12. background-color: #f3f3f3;
  13. }
  14. .ui.open.button{
  15. position: absolute;
  16. top: 0.6em;
  17. right: 1.2em;
  18. }
  19. .fileObject .fileCounter{
  20. position: absolute;
  21. top: 0.6em;
  22. right: 1.2em;
  23. background-color: #444444;
  24. color: white;
  25. padding: 4px;
  26. min-width: 40px;
  27. text-align: center;
  28. border-radius: 0.2em;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <br>
  34. <div class="ui container">
  35. <div class="ui segment">
  36. <div class="ui fluid icon input">
  37. <input id="keyword" type="text" placeholder="Search for Keyword" onkeydown="handleKeyDown(event);">
  38. <i class="inverted circular search link icon" onclick="search();"></i>
  39. </div>
  40. </div>
  41. <div class="ui divider"></div>
  42. <p id="resultsCount"></p>
  43. <div class="ui segment" id="searchResults">
  44. <div style="width: 100%;" align="center">
  45. <br>
  46. <h4 class="ui icon header">
  47. <i class="medium icons" style="color: #dbdbdb !important;">
  48. <i class="search icon"></i>
  49. </i>
  50. <div class="content" style="margin-top: 1em; color: #7c7c7c !important;">
  51. File Search
  52. <div class="sub header" style="color: #adadad !important;">This function will recursively search the whole SD card using keyword matching algorithm.<br>
  53. This might take a few minutes if you have a lots of files stored on your SD card.</div>
  54. </div>
  55. </h4>
  56. <br><br>
  57. </div>
  58. </div>
  59. <br><br><br>
  60. <!--
  61. <div class="ui fileObject segment">
  62. <h4 class="ui header" style="margin-bottom: 0px;">
  63. <img src="img/file.svg">
  64. <div class="content">
  65. <a>Filename</a>
  66. <div class="sub header">Filepath</div>
  67. </div>
  68. </h4>
  69. <p class="fileCounter">1</p>
  70. </div>
  71. -->
  72. </div>
  73. <script>
  74. function search(){
  75. let keyword = $("#keyword").val();
  76. let startTime = Date.now();
  77. $("#searchResults").html(`
  78. <div class="ui active inverted dimmer" style="height: 200px;">
  79. <div class="ui text loader">Scanning recursively...</div>
  80. </div>
  81. `);
  82. $.get("/api/fs/search?keyword=" + keyword, function(data){
  83. $("#searchResults").empty();
  84. if (data.length == 0){
  85. //Nothing found
  86. $("#searchResults").html(`<div style="width: 100%;" align="center">
  87. <br>
  88. <h4 class="ui icon header">
  89. <i class="medium icons" style="color: #dbdbdb !important;">
  90. <i class="red times icon"></i>
  91. </i>
  92. <div class="content" style="margin-top: 1em; color: #7c7c7c !important;">
  93. No Results
  94. <div class="sub header" style="color: #adadad !important;">This search engine is only capable of filename keyword search and not fuzzy search. Make sure you only enter the critical keywords.</div>
  95. </div>
  96. </h4>
  97. <br><br>
  98. </div>`);
  99. }else{
  100. let counter = 1;
  101. data.forEach(function(filepath){
  102. let filename = filepath.split("/").pop();
  103. $("#searchResults").append(`<div class="ui fileObject segment">
  104. <h4 class="ui header" style="margin-bottom: 0px;">
  105. <img src="img/file.svg">
  106. <div class="content">
  107. <a href="/api/fs/download?file=${filepath}&preview=true" target="_blank">${filename}</a>
  108. <div class="sub header">${filepath}</div>
  109. </div>
  110. </h4>
  111. <p class="fileCounter">${counter}</p>
  112. </div>`);
  113. counter++;
  114. });
  115. }
  116. $("#resultsCount").text(data.length + " results in " + (Date.now() - startTime)/1000 + " seconds");
  117. })
  118. }
  119. function handleKeyDown(e){
  120. if (e.keyCode == 13){
  121. e.preventDefault();
  122. search();
  123. }
  124. }
  125. //Check login status
  126. function initLoginCheck(){
  127. $.get("/api/auth/chk", function(data){
  128. if (data == false){
  129. window.location.href = "/login.html"
  130. }
  131. });
  132. }
  133. initLoginCheck();
  134. </script>
  135. </body>
  136. </html>