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

Function createFileEntry

public/js/upload.js:917–1042  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

915----------------------------------------------------- */
916// Create a file entry element with a remove button and a pause/resume button.
917function createFileEntry(file) {
918 const li = document.createElement("li");
919 li.classList.add("upload-progress-item");
920 li.style.display = "flex";
921 li.dataset.uploadIndex = file.uploadIndex;
922
923 // Remove button (always added)
924 const removeBtn = document.createElement("button");
925 removeBtn.classList.add("remove-file-btn");
926 removeBtn.textContent = "×";
927 // In your remove button event listener, replace the fetch call with:
928 removeBtn.addEventListener("click", function (e) {
929 e.stopPropagation();
930 const uploadIndex = file.uploadIndex;
931 window.selectedFiles = window.selectedFiles.filter(f => f.uploadIndex !== uploadIndex);
932
933 // Cancel the file upload if possible.
934 if (typeof file.cancel === "function") {
935 file.cancel();
936 console.log("Canceled file upload:", file.fileName);
937 }
938
939 // Remove file from the resumable queue.
940 if (resumableInstance && typeof resumableInstance.removeFile === "function") {
941 resumableInstance.removeFile(file);
942 }
943
944 // Call our helper repeatedly to remove the chunk folder.
945 if (file.uniqueIdentifier) {
946 removeChunkFolderRepeatedly(file.uniqueIdentifier, window.csrfToken, file.targetFolder, 3, 1000);
947 }
948
949 li.remove();
950 updateFileInfoCount();
951 const anyItems = !!document.querySelector('li.upload-progress-item');
952 setUploadButtonVisible(anyItems);
953 });
954 li.removeBtn = removeBtn;
955 li.appendChild(removeBtn);
956
957 // Add pause/resume/restart button if the file supports pause/resume.
958 // Conditionally add the pause/resume button only if file.pause is available
959 // Pause/Resume button (for resumable file–picker uploads)
960 if (typeof file.pause === "function") {
961 const pauseResumeBtn = document.createElement("button");
962 pauseResumeBtn.setAttribute("type", "button"); // not a submit button
963 pauseResumeBtn.classList.add("pause-resume-btn");
964 // Start with pause icon and disable button until upload starts
965 pauseResumeBtn.innerHTML = '<span class="material-icons pauseResumeBtn">pause_circle_outline</span>';
966 pauseResumeBtn.disabled = true;
967 pauseResumeBtn.addEventListener("click", function (e) {
968 e.stopPropagation();
969 if (file.isError) {
970 // If the file previously failed, try restarting upload.
971 if (typeof file.retry === "function") {
972 file.retry();
973 file.isError = false;
974 pauseResumeBtn.innerHTML = '<span class="material-icons pauseResumeBtn">pause_circle_outline</span>';

Callers 2

processFilesFunction · 0.85
initResumableUploadFunction · 0.85

Calls 5

updateFileInfoCountFunction · 0.85
setUploadButtonVisibleFunction · 0.85
displayFilePreviewFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected