@@ -54,10 +54,10 @@ var file = function(path, _config = false) {
54
54
55
55
if ( isServer ( path ) )
56
56
{
57
- if ( inArray ( fileExtension ( path ) , compressedExtensions . all ) || ! containsCompressed ( path ) )
57
+ if ( ! containsCompressed ( path ) )
58
58
files = await this . readServer ( path , _realPath ) ;
59
59
else
60
- files = await this . readInsideCompressedServer ( path , _realPath ) ;
60
+ files = await this . readServerCompressed ( path , _realPath ) ;
61
61
}
62
62
else if ( containsCompressed ( path ) )
63
63
{
@@ -282,8 +282,6 @@ var file = function(path, _config = false) {
282
282
let sha = sha1 ( path ) ;
283
283
let cacheFile = 'server-files-' + sha + '.json' ;
284
284
285
- let _containsCompressed = containsCompressed ( path , 0 , false ) ;
286
-
287
285
if ( this . config . cache && ( this . config . cacheOnly || this . config . cacheServer || serverInOfflineMode ) )
288
286
{
289
287
let json = cache . readJson ( cacheFile ) ;
@@ -298,42 +296,108 @@ var file = function(path, _config = false) {
298
296
if ( this . config . cacheOnly )
299
297
throw new Error ( 'notCacheOnly' ) ;
300
298
301
- let files = [ ] ;
299
+ let files = await serverClient . read ( path ) ;
300
+
301
+ return files ;
302
+
303
+ }
304
+
305
+ this . readServerCompressed = async function ( path = false , _realPath = false ) {
306
+
307
+ path = serverClient . fixPath ( path || this . path ) ;
308
+ _realPath = _realPath || realPath ( path , - 1 ) ;
309
+
310
+ if ( inArray ( fileExtension ( path ) , compressedExtensions . all ) )
311
+ return this . _readServerCompressed ( path , _realPath ) ;
312
+ else
313
+ return this . readServerInsideCompressed ( path , _realPath ) ;
314
+ }
315
+
316
+ this . _readServerCompressed = async function ( path = false , _realPath = false ) {
317
+
318
+ path = serverClient . fixPath ( path || this . path ) ;
319
+ _realPath = _realPath || realPath ( path , - 1 ) ;
302
320
303
- if ( _containsCompressed )
321
+ if ( this . config . cache && ( this . config . cacheOnly || this . config . cacheServer || serverInOfflineMode ) )
304
322
{
305
- let firstCompressed = firstCompressedFile ( path , 0 ) ;
323
+ let files = false ;
324
+
325
+ const cacheOnly = this . config . cacheOnly ;
326
+ this . updateConfig ( { cacheOnly : true } ) ;
306
327
307
- if ( ! fs . existsSync ( realPath ( firstCompressed ) ) )
328
+ try
329
+ {
330
+ files = await this . readCompressed ( path , _realPath ) ;
331
+ }
332
+ catch ( error )
333
+ {
334
+ if ( ! error . message || ! / n o t C a c h e O n l y / . test ( error . message ) )
335
+ throw new Error ( error ) ;
336
+ }
337
+
338
+ this . updateConfig ( { cacheOnly : cacheOnly } ) ;
339
+
340
+ if ( this . config . cacheOnly )
341
+ throw new Error ( 'notCacheOnly' ) ;
342
+
343
+ if ( files !== false )
344
+ return files ;
345
+ }
346
+
347
+ let firstCompressed = firstCompressedFile ( path , 0 ) ;
348
+
349
+ if ( firstCompressed )
350
+ {
351
+ if ( ! serverClient . existsSync ( realPath ( firstCompressed , - 1 ) ) )
308
352
{
309
353
// Download file to tmp
310
354
let file = await serverClient . download ( path , { only : [ firstCompressed ] } ) ;
311
355
312
356
if ( this . config . fromThumbnailsGeneration )
313
357
downloadedCompressedFile ( firstCompressed ) ;
314
358
}
315
-
316
- return this . readCompressed ( path ) ;
317
- }
318
- else
319
- {
320
- files = await serverClient . read ( path ) ;
321
359
}
322
360
323
- return files ;
361
+ return this . readCompressed ( path , _realPath ) ;
324
362
325
363
}
326
364
327
- this . readInsideCompressedServer = async function ( path = false , _realPath = false ) {
365
+ this . readServerInsideCompressed = async function ( path = false , _realPath = false ) {
328
366
329
367
path = path || this . path ;
330
368
_realPath = _realPath || realPath ( path , - 1 ) ;
331
369
370
+ if ( this . config . cache && ( this . config . cacheOnly || this . config . cacheServer || serverInOfflineMode ) )
371
+ {
372
+ let files = false ;
373
+
374
+ const cacheOnly = this . config . cacheOnly ;
375
+ this . updateConfig ( { cacheOnly : true } ) ;
376
+
377
+ try
378
+ {
379
+ files = await this . readInsideCompressed ( path , _realPath ) ;
380
+ }
381
+ catch ( error )
382
+ {
383
+ if ( ! error . message || ! / n o t C a c h e O n l y / . test ( error . message ) )
384
+ throw new Error ( error ) ;
385
+ }
386
+
387
+ this . updateConfig ( { cacheOnly : cacheOnly } ) ;
388
+
389
+ if ( this . config . cacheOnly )
390
+ throw new Error ( 'notCacheOnly' ) ;
391
+
392
+ if ( files !== false )
393
+ return files ;
394
+ }
395
+
332
396
let firstCompressed = firstCompressedFile ( path , 0 ) ;
333
397
334
398
if ( firstCompressed )
335
399
{
336
- if ( ! fs . existsSync ( realPath ( firstCompressed ) ) )
400
+ if ( ! serverClient . existsSync ( realPath ( firstCompressed , - 1 ) ) )
337
401
{
338
402
// Download file to tmp
339
403
let file = await serverClient . download ( path , { only : [ firstCompressed ] } ) ;
@@ -412,7 +476,7 @@ var file = function(path, _config = false) {
412
476
}
413
477
else
414
478
{
415
- image = await this . _images ( reverse ? - 1 : 1 , _files , from , fromReached , poster , deep + 1 ) ;
479
+ image = await this . _images ( ( reverse ? - 1 : 1 ) , _files , from , fromReached , poster , deep + 1 ) ;
416
480
fromReached = image . fromReached ;
417
481
image = image . images [ 0 ] || false ;
418
482
}
@@ -552,7 +616,7 @@ var file = function(path, _config = false) {
552
616
try
553
617
{
554
618
let file = fileManager . file ( dirname ) ;
555
- file . updateConfig ( { ... this . config , ... { fastRead : true , specialFiles : true , sha : false , cacheServer : true } } ) ;
619
+ file . updateConfig ( { fastRead : true , specialFiles : true , sha : false , cacheServer : true } ) ;
556
620
let files = await file . read ( ) ;
557
621
558
622
let poster = this . _poster ( files ) ;
@@ -1306,7 +1370,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
1306
1370
fs . mkdirSync ( this . tmp ) ;
1307
1371
1308
1372
if ( this . config . only )
1309
- fs . writeFileSync ( this . tmpPartialExtraction , '' ) ;
1373
+ fs . writeFileSync ( this . tmpPartialExtraction , '' ) ;
1310
1374
}
1311
1375
else if ( ! this . config . only )
1312
1376
{
@@ -1941,7 +2005,6 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
1941
2005
1942
2006
console . time ( 'extract7z: ' + this . path ) ;
1943
2007
1944
- let only = this . config . only ;
1945
2008
let _this = this ;
1946
2009
1947
2010
const onlyLen = this . config . _only ? this . config . _only . length : false ;
0 commit comments