(files)
| 731 | } |
| 732 | |
| 733 | async function filterExistingUploads(files) { |
| 734 | const result = { files, autoStart: false }; |
| 735 | if (!Array.isArray(files) || files.length === 0) return result; |
| 736 | if (!hasFolderPaths(files)) return result; |
| 737 | |
| 738 | const payloadFiles = []; |
| 739 | files.forEach(file => { |
| 740 | const path = getUploadPathForFile(file); |
| 741 | if (!path) return; |
| 742 | const size = typeof file.size === 'number' |
| 743 | ? file.size |
| 744 | : (file.file && typeof file.file.size === 'number' ? file.file.size : null); |
| 745 | payloadFiles.push({ path, size }); |
| 746 | }); |
| 747 | |
| 748 | if (!payloadFiles.length) return result; |
| 749 | |
| 750 | const payload = { |
| 751 | folder: window.currentFolder || 'root', |
| 752 | files: payloadFiles |
| 753 | }; |
| 754 | const sourceId = getActiveUploadSourceId(); |
| 755 | if (sourceId) payload.sourceId = sourceId; |
| 756 | |
| 757 | const existingResult = await fetchExistingUploads(payload); |
| 758 | if (!existingResult || !Array.isArray(existingResult.existing) || existingResult.existing.length === 0) { |
| 759 | return result; |
| 760 | } |
| 761 | |
| 762 | const existing = existingResult.existing; |
| 763 | const existingCount = existing.length; |
| 764 | const sameCount = existing.filter(e => e && e.sameSize === true).length; |
| 765 | const diffCount = existingCount - sameCount; |
| 766 | |
| 767 | const choice = await showUploadConflictModal({ |
| 768 | total: payloadFiles.length, |
| 769 | existing: existingCount, |
| 770 | sameSize: sameCount, |
| 771 | diffSize: diffCount |
| 772 | }); |
| 773 | |
| 774 | if (choice === 'cancel') return { files: [], autoStart: false }; |
| 775 | if (choice === 'overwrite') return { files, autoStart: true }; |
| 776 | |
| 777 | const existingAny = new Set(existing.map(e => normalizeUploadPath(e.path))); |
| 778 | const existingSame = new Set( |
| 779 | existing.filter(e => e && e.sameSize === true).map(e => normalizeUploadPath(e.path)) |
| 780 | ); |
| 781 | |
| 782 | const filtered = files.filter(file => { |
| 783 | const path = getUploadPathForFile(file); |
| 784 | if (!path) return true; |
| 785 | if (choice === 'skip') { |
| 786 | return !existingAny.has(path); |
| 787 | } |
| 788 | return !existingSame.has(path); |
| 789 | }); |
| 790 |
no test coverage detected