-
Notifications
You must be signed in to change notification settings - Fork 68
feat(uploader): support individual configuration of file/image/video MIME type #427
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughPer-kind MIME configuration and handling added: Changes
Sequence DiagramsequenceDiagram
participant UI as User / UI
participant Editor as FluentEditor
participant Uploader as CustomUploader
participant Validator as ValidationLogic
UI->>Editor: open file picker (intent: image/file/video)
Editor->>Uploader: upload(range, files, kind)
activate Uploader
loop per file
Uploader->>Validator: validateFile(file, kind)
activate Validator
Validator->>Uploader: request accepted types
Uploader-->>Validator: getAccept(kind) -> accepted types
Validator->>Validator: check file.type / extension vs accepts
Validator-->>Uploader: valid / invalid
deactivate Validator
end
alt all files valid
Uploader->>Uploader: getFileUrls(files, range, kind)
Uploader->>Editor: success(urls)
Editor->>UI: insert content
else some invalid
Uploader->>Editor: fail(error)
Editor->>UI: show error
end
deactivate Uploader
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/fluent-editor/src/modules/custom-uploader.ts (1)
141-147: Bug: incorrect file reference in success/fail callbacks.The loop uses
files[i]butiis the index intoresult(anduploads), not the originalfilesarray. Sinceuploadsis a filtered subset offiles, this causes an index mismatch when some files fail validation.For example, if
files = [invalid, valid1, valid2], thenuploads = [valid1, valid2]. Wheni=0,result[0]corresponds touploads[0](valid1), but the callback incorrectly receivesfiles[0](invalid).Proposed fix
for (const [i, res] of result.entries()) { if (isString(res)) { - this.options.success.call(this, files[i], { index: range.index + i, length: 0 }) + this.options.success.call(this, uploads[i], { index: range.index + i, length: 0 }) } else { - this.options.fail.call(this, files[i], { index: range.index + i, length: 0 }) + this.options.fail.call(this, uploads[i], { index: range.index + i, length: 0 }) } }
🤖 Fix all issues with AI agents
In `@packages/fluent-editor/src/modules/custom-uploader.ts`:
- Line 93: The size check in the custom uploader currently uses a strict
less-than which rejects files exactly equal to the allowed limit; change the
validation that returns "mimeOk && file.size < this.options.maxSize" to allow
the maximum by using a less-than-or-equal comparison so the expression becomes
"mimeOk && file.size <= this.options.maxSize" (update the check where file.size
and this.options.maxSize are compared in custom-uploader.ts).
🧹 Nitpick comments (1)
packages/fluent-editor/src/modules/custom-uploader.ts (1)
58-66: Consider documenting thekind === 'file'behavior.When
kindis'file', the function returns all types unfiltered. This means file uploads accept any configured MIME type including image/video types. If this is intentional (to allow flexible file uploads), a brief comment would clarify the design choice.
| @@ -55,17 +93,17 @@ export class FileUploader extends Uploader { | |||
| return mimeOk && file.size < this.options.maxSize | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Off-by-one: file exactly at maxSize fails validation.
The condition file.size < this.options.maxSize rejects files whose size equals maxSize exactly. If the intent is "maximum allowed size," this should use <=.
Proposed fix
- return mimeOk && file.size < this.options.maxSize
+ return mimeOk && file.size <= this.options.maxSize🤖 Prompt for AI Agents
In `@packages/fluent-editor/src/modules/custom-uploader.ts` at line 93, The size
check in the custom uploader currently uses a strict less-than which rejects
files exactly equal to the allowed limit; change the validation that returns
"mimeOk && file.size < this.options.maxSize" to allow the maximum by using a
less-than-or-equal comparison so the expression becomes "mimeOk && file.size <=
this.options.maxSize" (update the check where file.size and this.options.maxSize
are compared in custom-uploader.ts).
2b27ba0 to
393dfa3
Compare
PR
close #419
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #419
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.