All files / src/lib/uploads isSameUploadedFileSelection.ts

25% Statements 1/4
0% Branches 0/4
100% Functions 0/0
25% Lines 1/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28                      10x                                
import type { ResumableMultipartUploadState } from "./types";
 
/**
 * Check whether the newly selected file matches the upload that has already
 * completed for this upload state.
 */
export function isSameUploadedFileSelection(
  state: ResumableMultipartUploadState,
  file: File,
): boolean {
  if (state.status !== "uploaded") {
    return false;
  }
 
  const uploadedFile = state.resumeState?.file;
  if (uploadedFile) {
    return (
      uploadedFile.name === file.name &&
      uploadedFile.size === file.size &&
      uploadedFile.lastModified === file.lastModified &&
      uploadedFile.type === file.type
    );
  }
 
  // Fall back to file name when resume metadata is unavailable.
  return state.fileName === file.name;
}