downloadPageFolder.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <title>{{filename}} - {{hostname}} File Share</title>
  7. <meta name="description" content="Folder shared from {{hostname}}">
  8. <!-- Facebook Meta Tags -->
  9. <meta property="og:url" content="{{requri}}">
  10. <meta property="og:type" content="website">
  11. <meta property="og:title" content="{{filename}}">
  12. <meta property="og:description" content="File shared from {{hostname}}">
  13. <meta property="og:image" content="{{opg_image}}">
  14. <!-- Twitter Meta Tags -->
  15. <meta name="twitter:card" content="summary_large_image">
  16. <meta property="twitter:domain" content="{{host}}">
  17. <meta property="twitter:url" content="{{requri}}">
  18. <meta name="twitter:title" content="{{filename}}">
  19. <meta name="twitter:description" content="File shared from {{hostname}}">
  20. <meta name="twitter:image" content="{{opg_image}}">
  21. <link rel="stylesheet" href="../../script/skeleton/offline.css">
  22. <link rel="stylesheet" href="../../script/skeleton/normalize.css">
  23. <link rel="stylesheet" href="../../script/skeleton/skeleton.css">
  24. <script type="application/javascript" src="../../script/jquery.min.js"></script>
  25. <link rel="icon" type="image/png" href="../../img/public/share/share.png" />
  26. <style>
  27. body{
  28. padding-bottom: 100px;
  29. }
  30. .bar{
  31. height: 12px;
  32. background-color: #1a1a1a;
  33. width: 100%;
  34. }
  35. .footer{
  36. position: fixed;
  37. bottom: 0px;
  38. height: 50px;
  39. width: 100%;
  40. background-color: #1a1a1a;
  41. padding: 20px;
  42. color: white;
  43. }
  44. .fileobject{
  45. cursor: pointer;
  46. }
  47. .fileobject:hover{
  48. background-color: #f5f5f5;
  49. }
  50. .fileobject.active{
  51. background-color: #f5f5f5ee;
  52. }
  53. .noselect{
  54. -webkit-touch-callout: none; /* iOS Safari */
  55. -webkit-user-select: none; /* Safari */
  56. -khtml-user-select: none; /* Konqueror HTML */
  57. -moz-user-select: none; /* Old versions of Firefox */
  58. -ms-user-select: none; /* Internet Explorer/Edge */
  59. user-select: none;
  60. }
  61. #filelistWrapper{
  62. position: relative;
  63. padding: 12px;
  64. border-top: 4px solid #ffe46c;
  65. -webkit-box-shadow: 11px 9px 23px 0px rgba(54,54,54,0.31);
  66. box-shadow: 11px 9px 23px 0px rgba(54,54,54,0.31);
  67. }
  68. td{
  69. word-break: break-all;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <div class="bar"></div>
  75. <br>
  76. <div class="container">
  77. <h5>{{hostname}} File Sharing</h5>
  78. <h3>{{filename}}</h3>
  79. <div class="row">
  80. <div class="one-half column">
  81. <table class="u-full-width">
  82. <thead>
  83. <tr>
  84. <th>Property</th>
  85. <th>Value</th>
  86. </tr>
  87. </thead>
  88. <tbody>
  89. <tr>
  90. <td>MIME Type</td>
  91. <td>{{mime}}</td>
  92. </tr>
  93. <tr>
  94. <td>Folder Size</td>
  95. <td>{{size}}</td>
  96. </tr>
  97. <tr>
  98. <td>File Counts</td>
  99. <td>{{filecount}}</td>
  100. </tr>
  101. <tr>
  102. <td>Last Modification Time</td>
  103. <td>{{modtime}}</td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. <a href="{{downloadurl}}" id="downloadLink"><button class="button-primary">Download All</button></a>
  108. <button id="sharebtn" onclick="share();">Share</button>
  109. <div style="margin-top: 10px;">
  110. <input type="checkbox" id="uncompressedCheck" name="uncompressed">
  111. <label for="uncompressedCheck" style="display: inline">Uncompressed</label>
  112. </div>
  113. <p style="font-size: 80%;"><b>Zipping duration depends on folder size and compression settings. Media files are best zipped without compression for faster processing.</b></p>
  114. <p>Request File ID: {{reqid}}<br>
  115. Request Timestamp: {{reqtime}}</p>
  116. <small>📂 Double click any item in the list to open or download</small>
  117. <script>
  118. document.getElementById('uncompressedCheck').addEventListener('change', function() {
  119. const downloadLink = document.getElementById('downloadLink');
  120. if (this.checked) {
  121. downloadLink.href = '{{downloadurl}}?compression_level=0';
  122. } else {
  123. downloadLink.href = '{{downloadurl}}';
  124. }
  125. });
  126. </script>
  127. </div>
  128. <div class="one-half column" id="filelistWrapper" style="overflow-y: auto; padding-right: 0.5em; min-height: 400px;">
  129. <table class="u-full-width">
  130. <thead>
  131. <tr>
  132. <th>Filename</th>
  133. <th>Type</th>
  134. <th>Size</th>
  135. </tr>
  136. </thead>
  137. <tbody id="folderList">
  138. </tbody>
  139. </table>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="footer">
  144. <div class="container">
  145. Cloud File Sharing Interface, Powered by <a style="color: white;" href="http://arozos.com">arozos</a>
  146. </div>
  147. </div>
  148. <script>
  149. var treeFileList = {{treelist}};
  150. var downloadUUID = `{{downloaduuid}}`;
  151. var currentViewingRoot = ".";
  152. var selectedFile = null;
  153. var stats = renderFileList(treeFileList["."]);
  154. // most files are already compressed media...
  155. if (stats.totalCompressedMediaSize / stats.totalFileSize >= 0.5) {
  156. document.getElementById('uncompressedCheck').checked = true;
  157. const downloadLink = document.getElementById('downloadLink');
  158. downloadLink.href = '{{downloadurl}}?compression_level=0';
  159. }
  160. handleWindowResize();
  161. $(window).on("resize", function(e){
  162. handleWindowResize();
  163. });
  164. if (location.protocol !== 'https:') {
  165. document.getElementById("sharebtn").remove()
  166. }
  167. function share(){
  168. let shareData = {
  169. title: "{{filename}}",
  170. text: '{{filename}} - File Share from {{hostname}}',
  171. url: window.location.href,
  172. }
  173. navigator.share(shareData).then(() =>
  174. function(){
  175. //Share succ
  176. }
  177. ).catch((e) =>
  178. function(){
  179. //Share failed
  180. }
  181. )
  182. }
  183. function handleWindowResize(){
  184. if (window.innerWidth < 550){
  185. //Assume mobile
  186. $(".footer").css("height", "20px");
  187. }else{
  188. $(".footer").css("height", "50px");
  189. }
  190. }
  191. function convertToBytes(sizeString) {
  192. // Remove any spaces and convert to uppercase
  193. sizeString = sizeString.replace(/\s+/g, '').toUpperCase();
  194. // Regular expression to match number and unit
  195. const matches = sizeString.match(/^([\d.]+)([KMGT]?B)$/i);
  196. if (!matches) {
  197. throw new Error('Invalid format');
  198. }
  199. const size = parseFloat(matches[1]);
  200. const unit = matches[2];
  201. // Conversion factors
  202. const units = {
  203. 'B': 1,
  204. 'KB': 1024,
  205. 'MB': 1024 ** 2,
  206. 'GB': 1024 ** 3,
  207. 'TB': 1024 ** 4
  208. };
  209. return Math.round(size * units[unit]);
  210. }
  211. function renderFileList(filelist){
  212. $("#folderList").html("");
  213. if (currentViewingRoot != "."){
  214. $("#folderList").append(`<tr class="fileobject noselect" ondblclick="event.preventDefault(); parentdir();">
  215. <td style="padding-left: 8px;" colspan="3" > ↩ Back</td>
  216. </tr>`);
  217. }
  218. // Add a div for thumbnail preview
  219. if (!$("#thumbnail-preview").length) {
  220. $("body").append(`
  221. <div id="thumbnail-preview" style="
  222. display: none;
  223. position: fixed;
  224. background: white;
  225. padding: 5px;
  226. border: 1px solid #ccc;
  227. border-radius: 5px;
  228. box-shadow: 0 0 10px rgba(0,0,0,0.2);
  229. z-index: 1000;
  230. ">
  231. <img style="max-width: 200px; max-height: 200px;" />
  232. </div>
  233. `);
  234. }
  235. var totalCompressedMediaSize = 0;
  236. var totalFileSize = 0;
  237. filelist.forEach(file => {
  238. var filetype = "File";
  239. var displayName = "";
  240. var isImage = false;
  241. if (file.IsDir == true){
  242. //Folder
  243. filetype = "Folder";
  244. displayName = "📁 " + file.Filename;
  245. }else{
  246. //File
  247. totalFileSize += convertToBytes(file.Filesize);
  248. var ext = file.Filename.split(".").pop();
  249. var icon = "📄"
  250. ext = ext.toLowerCase();
  251. if (ext == "mp3" || ext == "wav" || ext == "flac" || ext == "alac" || ext == "wma" || ext == "aac" || ext == "ogg" || ext == ""){
  252. icon = "🎵";
  253. if (ext != "wav") {
  254. totalCompressedMediaSize += convertToBytes(file.Filesize);
  255. }
  256. }else if (ext == "mp4" || ext == "avi" || ext == "webm" || ext == "mkv" || ext == "wmv" || ext == "mov" || ext == "rmvb" || ext == "rm"){
  257. icon = "🎞️";
  258. totalCompressedMediaSize += convertToBytes(file.Filesize);
  259. }else if (ext == "png" || ext == "jpeg" || ext == "jpg" || ext == "bmp" || ext == "gif" || ext == "webp" || ext == "avif"){
  260. icon = "🖼️";
  261. isImage = true;
  262. if (ext != "bmp") {
  263. totalCompressedMediaSize += convertToBytes(file.Filesize);
  264. }
  265. }
  266. displayName = icon + " " + file.Filename;
  267. }
  268. var filenameLinker = `<a href="../../share/download/${downloadUUID}/${file.RelPath}">${displayName}</a>`;
  269. if (file.IsDir == true){
  270. filenameLinker = `${displayName}`;
  271. }
  272. var tr = $(`<tr class="fileobject noselect" onclick="highlightThis(this);" filename="${file.Filename}" relpath="${file.RelPath}" type="${filetype.toLocaleLowerCase()}" ondblclick="event.preventDefault(); openThis(this);">
  273. <td style="padding-left: 8px;">${filenameLinker}</td>
  274. <td>${filetype}</td>
  275. <td>${file.Filesize}</td>
  276. </tr>`);
  277. // Add hover event for images
  278. if (isImage) {
  279. // Store the download URL as a data attribute
  280. tr.attr('data-download-url', `../../share/download/${downloadUUID}/${file.RelPath}`);
  281. // Add hover events to the entire row
  282. tr.hover(
  283. function(e) { // mouseenter
  284. var imgUrl = $(this).attr('data-download-url');
  285. $("#thumbnail-preview img").attr('src', imgUrl);
  286. $("#thumbnail-preview").css({
  287. display: 'block',
  288. left: e.pageX + 20,
  289. top: e.pageY + 20
  290. });
  291. },
  292. function() { // mouseleave
  293. $("#thumbnail-preview").hide();
  294. }
  295. );
  296. // Update thumbnail position on mouse move over the entire row
  297. tr.mousemove(function(e) {
  298. $("#thumbnail-preview").css({
  299. left: e.pageX + 20,
  300. top: e.pageY + 20
  301. });
  302. });
  303. }
  304. $("#folderList").append(tr);
  305. });
  306. // Add CSS to make the entire row hoverable
  307. $("<style>")
  308. .prop("type", "text/css")
  309. .html(`
  310. .fileobject { cursor: pointer; }
  311. .fileobject:hover { background-color: rgba(0,0,0,0.05); }
  312. `)
  313. .appendTo("head");
  314. return {
  315. totalCompressedMediaSize, totalFileSize
  316. }
  317. }
  318. //Went up one level
  319. function parentdir(){
  320. if (currentViewingRoot == "."){
  321. //Root dir. Do nothing
  322. }else{
  323. //Subdirs. travel up
  324. var dirinfo = currentViewingRoot.split("/");
  325. var nextDir = ".";
  326. if (currentViewingRoot.indexOf("/") < 0){
  327. //Parent dir will be root
  328. }else{
  329. dirinfo.pop();
  330. nextDir = dirinfo.join("/");
  331. }
  332. //Load the filelist
  333. if (treeFileList[nextDir] != undefined){
  334. currentViewingRoot = nextDir;
  335. renderFileList(treeFileList[nextDir]);
  336. }else{
  337. //Back to root on error
  338. currentViewingRoot = ".";
  339. renderFileList(treeFileList["."]);
  340. }
  341. }
  342. }
  343. function openThis(object){
  344. var targetFilename = $(object).attr("filename");
  345. var targetType = $(object).attr("type");
  346. var targetRelPath = $(object).attr("relpath");
  347. if (targetType == "folder"){
  348. //Folder. Build a new root file list for this
  349. var targetRenderList = treeFileList[targetRelPath];
  350. if (targetRenderList != undefined){
  351. currentViewingRoot = targetRelPath;
  352. renderFileList(targetRenderList);
  353. }
  354. }else{
  355. //File. Download it
  356. window.open("../../share/download/" + downloadUUID + "/" + targetRelPath)
  357. }
  358. }
  359. resizeDOMElement();
  360. function resizeDOMElement(){
  361. $("#filelistWrapper").css({
  362. height: window.innerHeight - $("#filelistWrapper").offset().top - 100,
  363. })
  364. }
  365. function highlightThis(object){
  366. $(".fileobject.active").removeClass("active");
  367. $(object).addClass("active");
  368. $("#activeFilename").text(" (" + $(object).attr("filename") +")");
  369. //Update the properties values
  370. selectedFile = $(object);
  371. }
  372. $(window).on("resize", function(){
  373. resizeDOMElement();
  374. })
  375. </script>
  376. </body>
  377. </html>