Skip to content

Conversation

@kagol
Copy link
Member

@kagol kagol commented Jan 21, 2026

PR

close #419

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #419

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • File uploader now supports per-category MIME configuration (file/image/video) and kind-aware acceptance, improving control over accepted uploads and explicit type-aware handling.
  • Documentation

    • Docs updated to describe the new mimetypes shape: either a global array or a per-type object, with examples and behavior clarifications for images, videos, and files.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the enhancement New feature or request label Jan 21, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Per-kind MIME configuration and handling added: mimetypes now accepts a global array or an object with file, image, and video arrays. Upload flow became kind-aware; kind is inferred or passed through to validation and upload APIs.

Changes

Cohort / File(s) Summary
Demo & Docs
packages/docs/fluent-editor/demos/file-upload.vue, packages/docs/fluent-editor/docs/demo/file-upload.md
Demo changed uploader mimetypes from a flat array to a per-kind object ({ file, image, video }). Docs updated to document `string[]
Core Uploader
packages/fluent-editor/src/modules/custom-uploader.ts
Introduces UploadKind and MimeTypesConfig. mimetypes type updated. Adds getAccept(kind), inferKind, filterFromArray, and makes validateFile, getFileUrls, and upload kind-aware (new optional kind parameter). Validation now supports per-kind MIME resolution.
Integration
packages/fluent-editor/src/config/index.ts
Passes type (kind) into this.quill.uploader.upload(range, files, type) to propagate kind through upload flow.
Theme / UI handlers
packages/fluent-editor/src/themes/snow.ts
Replaces inline mimetype filtering with (this.quill as FluentEditor).uploader.getAccept('<type>') for file/image/video handlers.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I hopped to sort each kind with care,

Images, videos, files — each in their lair.
A twitch, a nibble, a clever tweak,
Now pickers show only what you seek.
Hooray — neat uploads make my whiskers peek!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for individual/per-type MIME configuration for file/image/video uploads, which is the primary objective.
Linked Issues check ✅ Passed The PR implements per-type MIME configuration as requested in #419: type-aware mimetypes mapping, getAccept() filtering by kind, and updated validators/upload methods to use type parameter.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing per-type MIME configuration: file-upload.vue demo, documentation, custom-uploader core logic, config, and theme integration. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kagol/support-individual-mimetype

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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] but i is the index into result (and uploads), not the original files array. Since uploads is a filtered subset of files, this causes an index mismatch when some files fail validation.

For example, if files = [invalid, valid1, valid2], then uploads = [valid1, valid2]. When i=0, result[0] corresponds to uploads[0] (valid1), but the callback incorrectly receives files[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 the kind === 'file' behavior.

When kind is '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
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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).

@kagol kagol force-pushed the kagol/support-individual-mimetype branch from 2b27ba0 to 393dfa3 Compare January 21, 2026 12:30
@kagol kagol merged commit 3a8a0b6 into dev Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ [Feature]: 图片/文件上传如何实现点击图片图标只能选图片、点击文件图标只能选文件

2 participants