MCPcopy Create free account
hub / github.com/error311/FileRise / filterExistingUploads

Function filterExistingUploads

public/js/upload.js:733–803  ·  view source on GitHub ↗
(files)

Source from the content-addressed store, hash-verified

731}
732
733async 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

Callers 1

queueResumableFilesFunction · 0.85

Calls 8

hasFolderPathsFunction · 0.85
getUploadPathForFileFunction · 0.85
getActiveUploadSourceIdFunction · 0.85
fetchExistingUploadsFunction · 0.85
showUploadConflictModalFunction · 0.85
normalizeUploadPathFunction · 0.85
tFunction · 0.85
showToastFunction · 0.70

Tested by

no test coverage detected