Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Mac upload folder error #2259

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ui/src/views/dataset/component/UploadComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ const fileHandleChange = (file: any, fileList: UploadFiles) => {
fileList.splice(-1, 1) //移除当前超出大小的文件
return false
}

if (!isRightType(file?.name, form.value.fileType)) {
MsgError(t('views.document.upload.errorMessage2'))
if (file?.name !== '.DS_Store') {
MsgError(t('views.document.upload.errorMessage2'))
}
fileList.splice(-1, 1)
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some suggested improvements to the code:

  1. Remove Redundant Line: The line fileList.splice(-1, 1) can be removed since it is only executed when an error occurs and will not change the final state of the fileList.

  2. Use Conditional Statements Consistently: Ensure that all conditions follow a consistent structure.

  3. Move MsgError Call Outside Loop: If there might be multiple errors per upload attempt, consider moving the MsgError call outside the loop to avoid unnecessary processing for valid files.

  4. Check for .DS_Store File Explicitly: The condition if !file?.name !== '.DS_Store' looks redundant because you already check if the file extension is correct. Consider removing this part if appropriate.

Here's refactored version of the code with these improvements applied:

const fileHandleChange = (file: any, fileList: UploadFiles) => {
  // Check file type consistency
  console.log(form.value.fileType); // Debug statement to ensure form value is correct
  if (!isRightType(file?.name, form.value.fileType)) {
    MsgError(t('views.document.upload.errorMessage2'));
    return false;
  }

  // Remove current file if its size exceeds allowed limit
  if (file.size > MAX_SIZE) {
    fileList.splice(-1, 1);
  }

  return true; // Return true to indicate successful handling of the file
}

These changes streamline the function logic and improve readability while addressing potential issues.

Expand Down