@electerm/electerm-react 1.80.5 → 1.80.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,6 +28,7 @@ export default class TransportAction extends Component {
|
|
|
28
28
|
refsTransfers.add(this.id, this)
|
|
29
29
|
this.total = 0
|
|
30
30
|
this.transferred = 0
|
|
31
|
+
this.currentProgress = 1
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
componentDidMount () {
|
|
@@ -421,11 +422,11 @@ export default class TransportAction extends Component {
|
|
|
421
422
|
}
|
|
422
423
|
this.transferred += transferred
|
|
423
424
|
const up = {}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
up.percent =
|
|
425
|
+
|
|
426
|
+
// Increment progress slightly with each file/folder (but never exceed 99%)
|
|
427
|
+
this.currentProgress = Math.min(this.currentProgress + 0.2, 99)
|
|
428
|
+
|
|
429
|
+
up.percent = Math.floor(this.currentProgress)
|
|
429
430
|
up.status = 'active'
|
|
430
431
|
up.transferred = this.transferred
|
|
431
432
|
up.startTime = this.startTime
|
|
@@ -505,49 +506,157 @@ export default class TransportAction extends Component {
|
|
|
505
506
|
return transfer
|
|
506
507
|
}
|
|
507
508
|
|
|
508
|
-
|
|
509
|
+
// Handle file transfers in parallel batches
|
|
510
|
+
transferFiles = async (files, batch, transfer) => {
|
|
511
|
+
if (this.onCancel) {
|
|
512
|
+
return
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const { fromPath, toPath } = transfer
|
|
516
|
+
|
|
517
|
+
// Process files in batches
|
|
518
|
+
for (let i = 0; i < files.length; i += batch) {
|
|
519
|
+
if (this.onCancel) {
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const batchFiles = files.slice(i, i + batch)
|
|
524
|
+
const promises = batchFiles.map(file => {
|
|
525
|
+
if (this.onCancel) {
|
|
526
|
+
return Promise.resolve(0)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const fromItemPath = resolve(fromPath, file.name)
|
|
530
|
+
const toItemPath = resolve(toPath, file.name)
|
|
531
|
+
|
|
532
|
+
const itemTransfer = {
|
|
533
|
+
...transfer,
|
|
534
|
+
fromPath: fromItemPath,
|
|
535
|
+
toPath: toItemPath,
|
|
536
|
+
fromFile: file
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return this.transferFileAsSubTransfer(itemTransfer)
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
// Wait for all files in batch to complete
|
|
543
|
+
const results = await Promise.all(promises)
|
|
544
|
+
|
|
545
|
+
// Update progress once for the entire batch
|
|
546
|
+
const batchTotalSize = results.reduce((sum, size) => sum + size, 0)
|
|
547
|
+
if (batchTotalSize > 0) {
|
|
548
|
+
this.onFolderData(batchTotalSize)
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Handle folder transfers sequentially to prevent concurrency explosion
|
|
554
|
+
transferFolders = async (folders, batch, transfer) => {
|
|
555
|
+
if (this.onCancel) {
|
|
556
|
+
return
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const { fromPath, toPath } = transfer
|
|
560
|
+
|
|
561
|
+
// Step 1: Create all folders concurrently in batches
|
|
562
|
+
for (let i = 0; i < folders.length; i += batch) {
|
|
563
|
+
if (this.onCancel) {
|
|
564
|
+
return
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const batchFolders = folders.slice(i, i + batch)
|
|
568
|
+
const createFolderPromises = batchFolders.map(folder => {
|
|
569
|
+
const toItemPath = resolve(toPath, folder.name)
|
|
570
|
+
|
|
571
|
+
// Create folder itself (don't process contents)
|
|
572
|
+
const createTransfer = {
|
|
573
|
+
...transfer,
|
|
574
|
+
toPath: toItemPath,
|
|
575
|
+
fromFile: folder
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return this.mkdir(createTransfer)
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
// Create all folders in this batch concurrently
|
|
582
|
+
await Promise.all(createFolderPromises)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Step 2: Process contents of each folder sequentially
|
|
586
|
+
for (const folder of folders) {
|
|
587
|
+
if (this.onCancel) {
|
|
588
|
+
return
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const fromItemPath = resolve(fromPath, folder.name)
|
|
592
|
+
const toItemPath = resolve(toPath, folder.name)
|
|
593
|
+
|
|
594
|
+
const itemTransfer = {
|
|
595
|
+
...transfer,
|
|
596
|
+
fromPath: fromItemPath,
|
|
597
|
+
toPath: toItemPath,
|
|
598
|
+
fromFile: folder
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Transfer folder contents (set createFolder = false since we already created it)
|
|
602
|
+
await this.transferFolderRecursive(itemTransfer, false)
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Main recursive function using the separate handlers
|
|
607
|
+
transferFolderRecursive = async (transfer = this.getDefaultTransfer(), createFolder = true) => {
|
|
509
608
|
if (this.onCancel) {
|
|
510
609
|
return
|
|
511
610
|
}
|
|
512
611
|
const {
|
|
513
612
|
fromPath,
|
|
514
|
-
toPath,
|
|
515
613
|
typeFrom,
|
|
516
|
-
typeTo,
|
|
517
614
|
sessionId,
|
|
518
615
|
toFile,
|
|
519
616
|
isRenamed
|
|
520
617
|
} = transfer
|
|
521
|
-
|
|
618
|
+
|
|
619
|
+
if (createFolder && (!toFile || isRenamed)) {
|
|
522
620
|
const folderCreated = await this.mkdir(transfer)
|
|
523
621
|
if (!folderCreated) {
|
|
524
622
|
return
|
|
525
623
|
}
|
|
526
624
|
}
|
|
625
|
+
|
|
527
626
|
const list = await this.list(typeFrom, fromPath, sessionId)
|
|
627
|
+
const bigFileSize = 1024 * 1024
|
|
628
|
+
const smallFilesBatch = 30
|
|
629
|
+
const BigFilesBatch = 3
|
|
630
|
+
const foldersBatch = 50
|
|
528
631
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
632
|
+
const {
|
|
633
|
+
folders,
|
|
634
|
+
smallFiles,
|
|
635
|
+
largeFiles
|
|
636
|
+
} = list.reduce((p, c) => {
|
|
637
|
+
if (c.isDirectory) {
|
|
638
|
+
p.folders.push(c)
|
|
639
|
+
} else {
|
|
640
|
+
this.total += c.size
|
|
641
|
+
if (c.size < bigFileSize) {
|
|
642
|
+
p.smallFiles.push(c)
|
|
643
|
+
} else {
|
|
644
|
+
p.largeFiles.push(c)
|
|
645
|
+
}
|
|
532
646
|
}
|
|
533
|
-
|
|
534
|
-
|
|
647
|
+
return p
|
|
648
|
+
}, {
|
|
649
|
+
folders: [],
|
|
650
|
+
smallFiles: [],
|
|
651
|
+
largeFiles: []
|
|
652
|
+
})
|
|
535
653
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
toPath: toItemPath,
|
|
540
|
-
fromFile: item
|
|
541
|
-
}
|
|
654
|
+
// Process files with parallel batching
|
|
655
|
+
await this.transferFiles(smallFiles, smallFilesBatch, transfer)
|
|
656
|
+
await this.transferFiles(largeFiles, BigFilesBatch, transfer)
|
|
542
657
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
if (item.isDirectory) {
|
|
546
|
-
await this.transferFolderRecursive(itemTransfer)
|
|
547
|
-
} else {
|
|
548
|
-
await this.transferFileAsSubTransfer(itemTransfer)
|
|
549
|
-
}
|
|
550
|
-
}
|
|
658
|
+
// Process folders sequentially
|
|
659
|
+
await this.transferFolders(folders, foldersBatch, transfer)
|
|
551
660
|
}
|
|
552
661
|
|
|
553
662
|
onError = (e) => {
|