@@ -784,7 +784,7 @@ var file = function(path, _config = false) {
784784 }
785785
786786 if ( _path !== file . path ) // If it is different it is because it is not a compressed file
787- this . setTmpUsage ( _path ) ;
787+ fileManager . setTmpUsage ( _path ) ;
788788 }
789789
790790 if ( filesToDecompress )
@@ -842,41 +842,9 @@ var file = function(path, _config = false) {
842842 }
843843 }
844844
845- this . saveTmpUsage ( ) ;
846-
847845 return filesToDecompressNum ;
848846 }
849847
850- this . tmpUsage = [ ] ;
851-
852- this . setTmpUsage = function ( path ) {
853-
854- this . tmpUsage . push ( path ) ;
855-
856- }
857-
858- this . saveTmpUsage = function ( ) {
859-
860- let len = this . tmpUsage . length ;
861-
862- if ( len === 0 ) return ;
863-
864- let time = app . time ( ) ;
865- let tmpUsage = storage . get ( 'tmpUsage' ) ;
866-
867- for ( let i = 0 ; i < len ; i ++ )
868- {
869- let path = this . tmpUsage [ i ] ;
870-
871- if ( ! tmpUsage [ path ] ) tmpUsage [ path ] = { } ;
872- tmpUsage [ path ] . lastAccess = time ;
873- }
874-
875- storage . setThrottle ( 'tmpUsage' , tmpUsage ) ;
876- this . tmpUsage = [ ] ;
877-
878- }
879-
880848 this . macosScopedResources = [ ] ;
881849
882850 this . macosStartAccessingSecurityScopedResource = function ( path ) {
@@ -1105,15 +1073,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
11051073 this . setTmpUsage = function ( ) {
11061074
11071075 if ( this . path !== this . realPath )
1108- {
1109- let time = app . time ( ) ;
1110- let tmpUsage = storage . get ( 'tmpUsage' ) ;
1111-
1112- if ( ! tmpUsage [ this . realPath ] ) tmpUsage [ this . realPath ] = { } ;
1113- tmpUsage [ this . realPath ] . lastAccess = time ;
1114-
1115- storage . setThrottle ( 'tmpUsage' , tmpUsage ) ;
1116- }
1076+ fileManager . setTmpUsage ( this . realPath ) ;
11171077
11181078 }
11191079
@@ -2893,13 +2853,13 @@ function downloadedCompressedFile(path)
28932853
28942854function realPath ( path , index = 0 , prefixes = false )
28952855{
2896- let segments = splitPath ( path ) ;
2897- let len = segments . length ;
2856+ const segments = splitPath ( path ) ;
2857+ const len = segments . length ;
2858+ const numSegments = len + index ;
28982859
28992860 let virtualPath ;
29002861
29012862 let newPath = virtualPath = ( len > 0 ) ? ( isEmpty ( segments [ 0 ] ) ? '/' : segments [ 0 ] ) : '' ;
2902- let numSegments = len + index ;
29032863
29042864 if ( isServer ( path ) )
29052865 {
@@ -2923,31 +2883,94 @@ function realPath(path, index = 0, prefixes = false)
29232883 {
29242884 let extension = fileExtension ( newPath ) ;
29252885
2926- if ( extension && inArray ( extension , compressedExtensions . all ) /* && fs.existsSync(newPath) && !fs.statSync(newPath).isDirectory()*/ )
2886+ if ( extension )
29272887 {
2928- let sha = sha1 ( p . normalize ( virtualPath ) ) ;
2929-
2930- if ( prefixes )
2888+ if ( inArray ( extension , compressedExtensions . all ) /* && fs.existsSync(newPath) && !fs.statSync(newPath).isDirectory()*/ )
29312889 {
2932- for ( let ext in prefixes )
2890+ let sha = sha1 ( p . normalize ( virtualPath ) ) ;
2891+
2892+ if ( prefixes )
29332893 {
2934- if ( inArray ( extension , compressedExtensions [ ext ] ) )
2894+ for ( let ext in prefixes )
29352895 {
2936- sha = prefixes [ ext ] + '-' + sha ;
2896+ if ( inArray ( extension , compressedExtensions [ ext ] ) )
2897+ {
2898+ sha = prefixes [ ext ] + '-' + sha ;
29372899
2938- break ;
2900+ break ;
2901+ }
29392902 }
29402903 }
2904+
2905+ newPath = p . join ( tempFolder , sha ) ;
29412906 }
2907+ else if ( inArray ( extension , imageExtensions . convert ) && i + 1 === len )
2908+ {
2909+ const sha = sha1 ( p . dirname ( p . normalize ( virtualPath ) ) ) ;
29422910
2943- newPath = p . join ( tempFolder , sha ) ;
2911+ let image = p . basename ( virtualPath ) ;
2912+ image = image + '.png' ;
2913+
2914+ newPath = p . join ( tempFolder , sha , image ) ;
2915+ }
29442916 }
29452917 }
29462918 }
29472919
29482920 return newPath ;
29492921}
29502922
2923+ async function convertUnsupportedImages ( files )
2924+ {
2925+ const promises = [ ] ;
2926+
2927+ for ( let i = 0 , len = files . length ; i < len ; i ++ )
2928+ {
2929+ const file = files [ i ] ;
2930+ const path = file . path ;
2931+
2932+ if ( inArray ( fileExtension ( path ) , imageExtensions . convert ) ) // Convert unsupported images
2933+ promises . push ( workers . convertImage ( path ) ) ;
2934+ }
2935+
2936+ await Promise . all ( promises ) ;
2937+
2938+ return true ;
2939+ }
2940+
2941+ var tmpUsageST = false , tmpUsageQueue = [ ] ;
2942+
2943+ function setTmpUsage ( path )
2944+ {
2945+ tmpUsageQueue . push ( path ) ;
2946+
2947+ if ( tmpUsageST === false )
2948+ {
2949+ tmpUsageST = setTimeout ( function ( ) {
2950+
2951+ tmpUsageST = false ;
2952+
2953+ const len = tmpUsageQueue . length ;
2954+ if ( len === 0 ) return ;
2955+
2956+ const time = app . time ( ) ;
2957+ const tmpUsage = storage . get ( 'tmpUsage' ) ;
2958+
2959+ for ( let i = 0 ; i < len ; i ++ )
2960+ {
2961+ const path = tmpUsageQueue [ i ] ;
2962+
2963+ if ( ! tmpUsage [ path ] ) tmpUsage [ path ] = { } ;
2964+ tmpUsage [ path ] . lastAccess = time ;
2965+ }
2966+
2967+ storage . setThrottle ( 'tmpUsage' , tmpUsage ) ;
2968+ tmpUsageQueue = [ ] ;
2969+
2970+ } , 1000 ) ;
2971+ }
2972+ }
2973+
29512974var serverInOfflineMode = false ;
29522975
29532976function setServerInOfflineMode ( value = false )
@@ -3372,6 +3395,8 @@ module.exports = {
33723395 isParentPath : isParentPath ,
33733396 simpleExists : simpleExists ,
33743397 replaceReservedCharacters : replaceReservedCharacters ,
3398+ convertUnsupportedImages : convertUnsupportedImages ,
3399+ setTmpUsage : setTmpUsage ,
33753400 macosSecurityScopedBookmarks : macosSecurityScopedBookmarks ,
33763401 macosStartAccessingSecurityScopedResource : macosStartAccessingSecurityScopedResource ,
33773402 dirSize : dirSize ,
0 commit comments