1/** 2 * Created by xshanarain. 3 */ 4 5(function() { 6 7 var viewFileController = function($scope,$state,$rootScope,$cookies,$location,authService, utilsService) { 8 9 $scope.username = ""; 10 $scope.fileKey = ""; 11 $scope.fileName = ""; 12 $scope.fileSource = ""; 13 14 $scope.sName = ""; 15 $scope.sEmail = ""; 16 17 //https://docs.google.com/gview?url=http://writing.engr.psu.edu/workbooks/formal_report_template.doc&embedded=true 18 $scope.viewFileURL = ""; 19 $scope.downloadFileMimeType = ""; 20 $scope.downloadFileName = ""; 21 $scope.downloadFileBlob; 22 $scope.isPDF = false; 23 24 $scope.canDownload = false; 25 $scope.shouldNotify = false; 26 27 var pdfjsLib = window['pdfjs-dist/build/pdf']; 28 pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js'; 29 var pdfDoc = null, 30 pageNum = 1, 31 pageRendering = false, 32 pageNumPending = null, 33 scale = 0.8, 34 canvas = document.getElementById('the-canvas'), 35 ctx = canvas.getContext('2d'); 36 37 function renderPage(num) { 38 pageRendering = true; 39 // Using promise to fetch the page 40 pdfDoc.getPage(num).then(function(page) { 41 var viewport = page.getViewport(scale); 42 canvas.height = viewport.height; 43 canvas.width = viewport.width; 44 45 // Render PDF page into canvas context 46 var renderContext = { 47 canvasContext: ctx, 48 viewport: viewport 49 }; 50 var renderTask = page.render(renderContext); 51 52 // Wait for rendering to finish 53 renderTask.promise.then(function() { 54 pageRendering = false; 55 if (pageNumPending !== null) { 56 // New page rendering is pending 57 renderPage(pageNumPending); 58 pageNumPending = null; 59 } 60 }); 61 }); 62 63 // Update page counters 64 document.getElementById('page_num').textContent = num; 65 } 66 67 function queueRenderPage(num) { 68 if (pageRendering) { 69 pageNumPending = num; 70 } else { 71 renderPage(num); 72 } 73 } 74 75 function onPrevPage() { 76 if (pageNum <= 1) { 77 return; 78 } 79 pageNum--; 80 queueRenderPage(pageNum); 81 } 82 83 function onNextPage() { 84 if (pageNum >= pdfDoc.numPages) { 85 return; 86 } 87 pageNum++; 88 queueRenderPage(pageNum); 89 } 90 91 $scope.sendNotification = function (action) { 92 if ( $scope.shouldNotify ){ 93 utilsService.getSharedFileDetails($scope.username, $scope.fileName, $scope.fileKey, $scope.fileSource, 94 $scope.sName, $scope.sEmail, action) 95 .then(function(success) { 96 console.log(success.data) 97 },function(error){ 98 swal("Sorry!", error.data.message, "error"); 99 }); 100 } 101 }; 102 103 function downloadCurrentFile() { 104 saveAs($scope.downloadFileBlob, $scope.downloadFileName); 105 }; 106 107 $scope.showFile = function () { 108 debugger 109 110 $scope.sendNotification('viewed'); 111 document.getElementById('downloadFileBtn').addEventListener('click', downloadCurrentFile); 112 window.blobURL = URL.createObjectURL($scope.downloadFileBlob); 113 if ($scope.downloadFileMimeType === 'image/jpeg' || 114 $scope.downloadFileMimeType === 'image/png' || 115 $scope.downloadFileMimeType === 'image/g3fax' || 116 $scope.downloadFileMimeType === 'image/gif') { 117 var a = "<img src=" + window.blobURL + "\>"; 118 document.getElementById('byte_content').innerHTML = a; 119 } else if ($scope.downloadFileMimeType === 'audio/mpeg' || 120 $scope.downloadFileMimeType === 'audio/ogg' || 121 $scope.downloadFileMimeType === 'audio/*') { 122 var a = "<audio controls> <source src=" + window.blobURL + " type="+$scope.downloadFileMimeType+" > </audio>" 123 } else if ($scope.downloadFileMimeType === 'video/mpeg' || 124 $scope.downloadFileMimeType === 'video/ogg' || 125 $scope.downloadFileMimeType === 'video/*') { 126 var a = "<video controls> <source src=" + window.blobURL + " type=\"+$scope.downloadFileMimeType+\"> </video>" 127 } else if ($scope.downloadFileMimeType === "text/html" || 128 $scope.downloadFileMimeType === "text/plain" || 129 $scope.downloadFileMimeType === "application/javascript" || 130 $scope.downloadFileMimeType === "application/json" || 131 $scope.downloadFileMimeType === "text/css" || 132 $scope.downloadFileMimeType === "text/richtext" || 133 $scope.downloadFileMimeType === "text/x-java-source" || 134 $scope.downloadFileMimeType === "text/x-c" || 135 $scope.downloadFileMimeType === "text/csv") { 136 const reader = new FileReader(); 137 reader.onload = function(e) { 138 var data = e.target.result; 139 document.getElementById('byte_content').innerHTML = data; 140 } 141 reader.readAsBinaryString($scope.downloadFileBlob); 142 } else if ($scope.downloadFileMimeType === "application/pdf") { 143 $scope.isPDF = true; 144 $scope.$evalAsync(); 145 146 document.getElementById('prev').addEventListener('click', onPrevPage); 147 document.getElementById('next').addEventListener('click', onNextPage); 148 pdfjsLib.getDocument(window.blobURL).then(function(pdfDoc_) { 149 pdfDoc = pdfDoc_; 150 document.getElementById('page_count').textContent = pdfDoc.numPages; 151 152 // Initial/first page rendering 153 renderPage(pageNum); 154 }); 155 156 } else if ($scope.downloadFileMimeType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" || 157 $scope.downloadFileMimeType === 'application/msword') { 158 mammoth.convertToHtml({path: window.blobURL}) 159 .then(function(result){ 160 var html = result.value; // The generated HTML 161 document.getElementById('byte_content').innerHTML = html; 162 var messages = result.messages; // Any messages, such as warnings during conversion 163 swal("Sorry!", messages, "warning"); 164 }) 165 .done(); 166 } 167 }; 168 169 var init = function() { 170 171 $scope.username = $location.search().username; 172 $scope.fileKey = $location.search().key; 173 $scope.fileName = $location.search().fileName; 174 $scope.fileSource = $location.search().source; 175 $scope.sName = $location.search().sName;; 176 $scope.sEmail = $location.search().sEmail; 177 $scope.shouldNotify = $location.search().nm === "1"; 178 $scope.canDownload = $location.search().ad === "1"; 179 $scope.isPDF = false;
180 utilsService.getSharedFileDetails($scope.username, $scope.fileName, $scope.fileKey, $scope.fileSource) 181 .then(function(success) { 182 var _to = new Date(success.data.share_to); 183 if (_to > new Date()) { 184 var dFUrl = 'https://mycloudfish.com/app/libs/downloadShareFile.php?fileName=' + $scope.fileName 185 + "&fileKey=" + $scope.fileKey + "&fileSource=" + $scope.fileSource; 186 fetch(dFUrl).then(function (res) { 187 return res.blob(); 188 }).then(function (data) { 189 if (data) { 190 if ($scope.fileName.indexOf(".$enc") > 0) { 191 utilsService.getUserKey($scope.username).then(function(success) { 192 $scope.downloadFileName = $scope.fileName.replace(".$enc", ""); 193 $scope.downloadFileMimeType = utilsService.getExtention($scope.downloadFileName); 194 utilsService 195 .decryptFileObject(data, success.data.key, $scope.downloadFileMimeType) 196 .then(function (decBlob) { 197 $scope.downloadFileBlob = decBlob; 198 $scope.showFile(); 199 }) 200 .catch(function (err) { 201 swal("Sorry!", err.data, "error"); 202 }); 203 },function(error){ 204 swal("Sorry!", error.data, "error"); 205 }); 206 } else { 207 $scope.downloadFileBlob = data; 208 $scope.downloadFileName = $scope.fileName; 209 $scope.downloadFileMimeType = utilsService.getExtention($scope.downloadFileName); 210 $scope.showFile(); 211 //saveAs(data, $scope.fileName); 212 } 213 } 214 }).catch(function(err) { 215 swal("Sorry!", err.message, "error"); 216 }); 217 } else { 218 swal("Sorry!", "File has been expired!", "info"); 219 } 220 },function(error){ 221 swal("Sorry!", error.data.message, "error"); 222 }); 223 } 224 225 init(); 226 227 }; 228 229 viewFileController.$inject = ['$scope','$state','$rootScope','$cookies','$location', 'authService', 'utilsService']; 230 231 angular.module('authApp').controller('viewFileController', viewFileController); 232 233}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.