File indexing completed on 2024-12-22 05:34:44

0001 window.appHelpers = (function(){
0002 
0003   function getEnv(domain){
0004     let env;
0005     if (this.splitByLastDot(domain) === 'com' || this.splitByLastDot(domain) === 'org'){
0006       env = 'live';
0007     } else {
0008       env = 'test';
0009     }
0010     return env;
0011   }
0012 
0013   function getDeviceWidth(width){
0014     let device;
0015     if (width > 1720){
0016       device = "very-huge";
0017     } else if (width < 1720 && width > 1500){
0018       device = "huge";
0019     } else if (width < 1500 && width > 1250){
0020       device = "full";
0021     } else if (width < 1250 && width >= 1000){
0022       device = "large";
0023     } else if (width < 1000 && width >= 661){
0024       device = "mid";
0025     } else if (width < 661 && width >= 400){
0026       device = "tablet";
0027     } else if (width < 400){
0028       device = "phone"
0029     }
0030     return device;
0031   }
0032 
0033   function splitByLastDot(text) {
0034       var index = text.lastIndexOf('.');
0035       return text.slice(index + 1);
0036   }
0037 
0038   function getTimeAgo(datetime){
0039     const a = timeago().format(datetime);
0040     return a;
0041   }
0042 
0043   function getFileSize(size) {
0044     if (isNaN(size))
0045         size = 0;
0046 
0047     if (size < 1024)
0048         return size + ' Bytes';
0049 
0050     size /= 1024;
0051 
0052     if (size < 1024)
0053         return size.toFixed(2) + ' Kb';
0054 
0055     size /= 1024;
0056 
0057     if (size < 1024)
0058         return size.toFixed(2) + ' Mb';
0059 
0060     size /= 1024;
0061 
0062     if (size < 1024)
0063         return size.toFixed(2) + ' Gb';
0064 
0065     size /= 1024;
0066 
0067     return size.toFixed(2) + ' Tb';
0068         }
0069 
0070   function generateFilterUrl(location,currentCat){
0071     let link = {}
0072     if (currentCat && currentCat !== 0){
0073       link.base = "/browse/cat/" + currentCat + "/ord/";
0074     } else {
0075       link.base = "/browse/ord/";
0076     }
0077     if (location.search) link.search = location.search;
0078     return link;
0079   }
0080 
0081   function generateFileDownloadHash(file,env){
0082     let salt;
0083     if (env === "test"){
0084       salt = "vBHnf7bbdhz120bhNsd530LsA2mkMvh6sDsCm4jKlm23D186Fj";
0085     } else {
0086       salt = "Kcn6cv7&dmvkS40Hna§4ffcvl=021nfMs2sdlPs123MChf4s0K";
0087     }
0088 
0089     const timestamp =  Math.floor((new Date().getTime() / 1000)+3600)
0090     const hash = md5(salt+file.collection_id+timestamp);
0091     return hash;
0092   }
0093 
0094   return {
0095     getEnv,
0096     getDeviceWidth,
0097     splitByLastDot,
0098     getTimeAgo,
0099     getFileSize,
0100     generateFilterUrl,
0101     generateFileDownloadHash
0102   }
0103 
0104 }());