disk_restore.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>File Restore</title>
  5. <meta name="mobile-web-app-capable" content="yes">
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta charset="UTF-8">
  8. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  9. <script src="../../script/jquery.min.js"></script>
  10. <script src="../../script/semantic/semantic.min.js"></script>
  11. <script type="text/javascript" src="../../script/ao_module.js"></script>
  12. <style>
  13. .hidden{
  14. display:none;
  15. }
  16. .disabled{
  17. opacity: 0.5;
  18. pointer-events: none;
  19. }
  20. .colorblock{
  21. width: 20px;
  22. height: 20px;
  23. display: inline-block;
  24. vertical-align: bottom;
  25. margin-right: 12px;
  26. }
  27. .blue.colorblock{
  28. background-color: #52bdf2;
  29. }
  30. .grey.colorblock{
  31. background-color: #b9b9b9;
  32. }
  33. .yellow.colorblock{
  34. background-color: #e5e75c;
  35. }
  36. .ui.table tr td{
  37. border-top: 0px solid transparent !important;
  38. }
  39. .overlap.bar{
  40. position: absolute !important;
  41. top:0px;
  42. left: 0px;
  43. }
  44. .nointeract{
  45. pointer-events: none;
  46. user-select: none;
  47. }
  48. #restorableList{
  49. max-height: 300px;
  50. overflow-y: scroll;
  51. padding-right: 4px;
  52. }
  53. .timeleft{
  54. width: 30px;
  55. height: 30px;
  56. display: inline-block;
  57. user-select: none;
  58. vertical-align: baseline;
  59. margin-bottom: -10px;
  60. margin-right: 4px;
  61. }
  62. .closebtn{
  63. position: absolute;
  64. right: 4px;
  65. top: 4px;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <br>
  71. <div class="ui container">
  72. <h3 class="ui header">
  73. Backup & Restore
  74. <div class="sub header">Show restore points for the selected virtual disk</div>
  75. </h3>
  76. <div class="ui divider"></div>
  77. <div id="error" class="ui red inverted segment hidden">
  78. <h4 class="ui header">
  79. <i class="remove icon"></i>
  80. <div class="content">
  81. List Restore Failed
  82. <div class="sub reason header" style="color: white;">Unknown Vroot paramter given</div>
  83. </div>
  84. </h4>
  85. </div>
  86. <div id="succ" class="ui green inverted segment" style="display:none;">
  87. <h4 class="ui header">
  88. <i class="checkmark icon"></i>
  89. <div class="content">
  90. File Restored
  91. <div class="sub reason header openfolder" style="color: white;"><span style="cursor: pointer" onclick="handleOpenRestoreLocation()"><i class="ui folder icon"></i> Open Restore Location</span></div>
  92. </div>
  93. </h4>
  94. </div>
  95. <div id="fileinfo" class="ui segment" style="display:none;">
  96. <h4 class="ui header">
  97. <div class="content">
  98. <span class="filename">No File Selected</span>
  99. <div class="sub header relpath">N/A</div>
  100. </div>
  101. </h4>
  102. <div class="ui divider"></div>
  103. <h5>Restorable File Properties</h5>
  104. <span class="backupDisk">N/A</span><br>
  105. <span class="restorePoint">N/A</span><br>
  106. <span class="deleteTime">N/A</span><br>
  107. <span class="deleteRemainingTime">N/A</span><br>
  108. <button class="circular ui icon basic small button closebtn" onclick='$("#fileinfo").slideUp("fast");'>
  109. <i class="icon remove"></i>
  110. </button>
  111. </div>
  112. <div id="restorableList" class="ui middle aligned divided list">
  113. <div class="item">
  114. <img class="ui mini image nointeract" src="../../img/system/file-notfound.svg">
  115. <div class="content">
  116. No Restorable File(s) for this virtual disk.
  117. </div>
  118. </div>
  119. </div>
  120. <div class="ui checkbox">
  121. <input type="checkbox" name="showhidden" autocomplete="false" onchange="toggleHiddenFiles(this.checked);">
  122. <label>Show hidden / cache files</label>
  123. </div>
  124. <div class="ui divider" style="margin-top: 8px; margin-bottom: 8px;"></div>
  125. <br>
  126. <button class="ui right floated button" onclick="ao_module_close();">Close</button>
  127. <br>
  128. </div>
  129. <br><br>
  130. <script>
  131. var vrootID = "";
  132. $(".ui.checkbox").checkbox();
  133. //Extract vroot id from the window hash
  134. if (window.location.hash.length > 1){
  135. vrootID = JSON.parse(decodeURIComponent(window.location.hash.substr(1)));
  136. if (vrootID.length >= 1){
  137. //At least 1 vroot is passed in
  138. listRestorableFiles(vrootID[0]);
  139. }else{
  140. $("#error").removeClass("hidden");
  141. }
  142. }else{
  143. $("#error").removeClass("hidden");
  144. }
  145. function showFileInfo(object){
  146. var filedata = $(object).attr("filedata");
  147. filedata = JSON.parse(decodeURIComponent(filedata));
  148. console.log(filedata);
  149. //Show information on page
  150. $("#fileinfo").find(".filename").text(filedata.Filename + ` (${ao_module_utils.formatBytes(filedata.Filesize, 2)})`);
  151. //Hide the filename in relpath
  152. var shortenRelpath = filedata.RelpathOnDisk.split("/");
  153. shortenRelpath.pop();
  154. shortenRelpath = shortenRelpath.join("/") + "/";
  155. $("#fileinfo").find(".relpath").text(shortenRelpath);
  156. $("#fileinfo").find(".backupDisk").html('<i class="ui blue disk icon"></i> Restorable file from ' + filedata.BackupDiskUID + ":/");
  157. $("#fileinfo").find(".deleteTime").html('<i class="ui trash icon"></i> File deleted since ' + timeConverter(filedata.DeleteTime));
  158. $("#fileinfo").find(".restorePoint").html('<i class="ui refresh icon"></i> Restore to ' + (filedata.RestorePoint));
  159. $("#fileinfo").find(".deleteRemainingTime").html('<i class="ui red remove icon"></i> Auto delete in '+ secondsToHms(filedata.RemainingTime));
  160. $("#fileinfo").slideDown('fast');
  161. }
  162. function secondsToHms(d) {
  163. d = Number(d);
  164. var h = Math.floor(d / 3600);
  165. var m = Math.floor(d % 3600 / 60);
  166. var s = Math.floor(d % 3600 % 60);
  167. var hDisplay = h > 0 ? h.toString().padStart(2, "0") + (h == 1 ? " hour, " : " hours, ") : "";
  168. var mDisplay = m > 0 ? m.toString().padStart(2, "0") + (m == 1 ? " minute, " : " minutes") : "";
  169. return hDisplay + mDisplay;
  170. }
  171. function timeConverter(UNIX_timestamp){
  172. var a = new Date(UNIX_timestamp * 1000);
  173. var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  174. var year = a.getFullYear();
  175. var month = months[a.getMonth()];
  176. var date = a.getDate();
  177. var hour = a.getHours().toString().padStart(2, "0");
  178. var min = a.getMinutes().toString().padStart(2, "0");
  179. var sec = a.getSeconds().toString().padStart(2, "0");
  180. var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
  181. return time;
  182. }
  183. function toggleHiddenFiles(status=undefined){
  184. if (status == undefined){
  185. $(".hiddenfile").slideToggle("fast");
  186. }else if (status == true){
  187. $(".hiddenfile").slideDown("fast");
  188. }else if (status == false){
  189. $(".hiddenfile").slideUp("fast");
  190. }
  191. }
  192. //Restore this file
  193. var restoreFileInfo = undefined;
  194. function restoreThisFile(fileObject){
  195. var filedata = $(fileObject).attr("filedata");
  196. filedata = JSON.parse(decodeURIComponent(filedata));
  197. console.log(filedata);
  198. $.ajax({
  199. url: "../../system/backup/restoreFile",
  200. method: "POST",
  201. data: {"bdid": filedata.BackupDiskUID, "relpath": filedata.RelpathOnDisk},
  202. success: function(data){
  203. $("#succ").slideDown('fast').delay(10000).slideUp('fast');
  204. if (data.error !== undefined){
  205. alert("Restore failed: " + data.error);
  206. }else{
  207. console.log(data);
  208. restoreFileInfo = data;
  209. if (restoreFileInfo.RestoredVirtualPath == ""){
  210. $("#openfolder").hide();
  211. }else{
  212. $("#openfolder").show();
  213. }
  214. }
  215. }
  216. })
  217. }
  218. function handleOpenRestoreLocation(){
  219. if (restoreFileInfo.RestoredVirtualPath != undefined && restoreFileInfo.RestoredVirtualPath != ""){
  220. var filepath = restoreFileInfo.RestoredVirtualPath;
  221. var tmp = filepath.split("/");
  222. var filename = tmp.pop();
  223. var dirname = tmp.join("/");
  224. ao_module_openPath(dirname, filename);
  225. }
  226. }
  227. function listRestorableFiles(rootID){
  228. $.ajax({
  229. url: "/system/backup/listRestorable",
  230. data: {vroot: rootID},
  231. success: function(data){
  232. if (data.error !== undefined){
  233. $("#error").find(".reason").texxt(data.error);
  234. }else{
  235. //Sort the result by latest first
  236. data.RestorableFiles.sort(function(a, b) {
  237. return b.DeleteTime - a.DeleteTime;
  238. });
  239. //Display the result
  240. $("#restorableList").html("");
  241. data.RestorableFiles.forEach(fileObject => {
  242. let thisFileData = encodeURIComponent(JSON.stringify(fileObject));
  243. var timerIcon = "100.svg";
  244. if (fileObject.RemainingTime < 75600){
  245. timerIcon = "87_5.svg"
  246. }else if (fileObject.RemainingTime < 64800){
  247. timerIcon = "75.svg"
  248. }else if (fileObject.RemainingTime < 54000){
  249. timerIcon = "62_5.svg"
  250. }else if (fileObject.RemainingTime < 43200){
  251. timerIcon = "50.svg"
  252. }else if (fileObject.RemainingTime < 32400){
  253. timerIcon = "37_5.svg"
  254. }else if (fileObject.RemainingTime < 21600){
  255. timerIcon = "25.svg"
  256. }else if (fileObject.RemainingTime < 10800){
  257. timerIcon = "12_5.svg"
  258. }else if (fileObject.RemainingTime < 7200){
  259. timerIcon = "0.svg"
  260. }
  261. var deleteTimeLeftHumanReadable = secondsToHms(fileObject.RemainingTime);
  262. var fileIcon = "../../img/system/file-restore.svg";
  263. var isHidden = "";
  264. if (fileObject.IsHidden == true){
  265. fileIcon = "../../img/system/file-restore-hidden.svg";
  266. isHidden = "hiddenfile";
  267. }
  268. $("#restorableList").append(`<div class="item restorableFile ${isHidden}" filedata="${thisFileData}">
  269. <div class="right floated content">
  270. <div class="timeleft" title="Will be deleted in ${deleteTimeLeftHumanReadable}">
  271. <img class="ui fluid image" src="../../img/icons/backup/${timerIcon}"/>
  272. </div>
  273. <div class="ui tiny button" onclick="showFileInfo(this.parentNode.parentNode)">Info</div>
  274. <div class="ui tiny green button" onclick="restoreThisFile($(this).parent().parent());">Restore</div>
  275. </div>
  276. <div class="content">
  277. <p style="word-break: break-all;"><img class="ui mini spaced image nointeract" src="${fileIcon}">
  278. ${fileObject.Filename}
  279. </p>
  280. </div>
  281. </div>`);
  282. });
  283. $(".hiddenfile").hide();
  284. }
  285. }
  286. })
  287. }
  288. </script>
  289. </body>
  290. </html>