Skip to content

fix(editor): get max file size from blob sync engine #11923

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

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

fundon
Copy link
Contributor

@fundon fundon commented Apr 23, 2025

Closes: BS-3287

What's Changed!

  • Removed FileSizeLimitService
  • Added maxFileSize getter to BlobSync engine

Summary by CodeRabbit

  • Refactor

    • Consolidated file size limit logic by removing the File Size Limit Service and directly accessing file size limits from relevant storage or engine properties.
    • Centralized file size validation and user notifications for attachments and images into reusable helper functions.
    • Updated related function signatures to streamline parameters and improve maintainability.
  • New Features

    • Introduced a default maximum file size for uploads, with logic to retrieve this value from the storage engine or workspace configuration.
  • Style

    • Improved code consistency by unifying how file size limits are accessed across the application.
  • Chores

    • Removed unused internal services and related exports to reduce codebase complexity.

Copy link
Contributor Author

fundon commented Apr 23, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fundon fundon force-pushed the fundon/04_23_get_maxFileSize_from_blobSync branch from 1b084a6 to e221fc2 Compare April 23, 2025 08:56
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 32.55814% with 29 lines in your changes missing coverage. Please review.

Project coverage is 55.88%. Comparing base (9c0633b) to head (862b16b).
Report is 10 commits behind head on canary.

Files with missing lines Patch % Lines
blocksuite/affine/blocks/image/src/utils.ts 32.00% 17 Missing ⚠️
blocksuite/affine/blocks/attachment/src/utils.ts 50.00% 5 Missing ⚠️
...d/core/src/modules/workspace/entities/workspace.ts 0.00% 2 Missing ⚠️
...e/affine/blocks/attachment/src/attachment-block.ts 0.00% 1 Missing ⚠️
blocksuite/affine/blocks/attachment/src/embed.ts 0.00% 1 Missing ⚠️
.../affine/blocks/image/src/commands/insert-images.ts 0.00% 1 Missing ⚠️
...locksuite/affine/blocks/image/src/image-service.ts 0.00% 1 Missing ⚠️
blocksuite/framework/sync/src/blob/engine.ts 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           canary   #11923      +/-   ##
==========================================
- Coverage   55.88%   55.88%   -0.01%     
==========================================
  Files        2588     2594       +6     
  Lines      115007   115059      +52     
  Branches    18554    18566      +12     
==========================================
+ Hits        64277    64299      +22     
+ Misses      49364    48781     -583     
- Partials     1366     1979     +613     
Flag Coverage Δ
server-test 79.20% <ø> (ø)
unittest 31.45% <2.32%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fundon fundon force-pushed the fundon/04_23_get_maxFileSize_from_blobSync branch 3 times, most recently from b995774 to 5c256c8 Compare April 23, 2025 09:32
@fundon fundon force-pushed the fundon/04_23_get_maxFileSize_from_blobSync branch 3 times, most recently from 28b2126 to fe40ed2 Compare April 23, 2025 09:50
@fundon fundon marked this pull request as ready for review April 23, 2025 11:47
@fundon fundon requested a review from a team as a code owner April 23, 2025 11:47
@graphite-app graphite-app bot requested review from a team April 23, 2025 11:48
Copy link
Contributor

@Saul-Mirone Saul-Mirone left a comment

Choose a reason for hiding this comment

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

LGTM

private readonly onReachedMaxBlobSizeCallbacks: Set<
(byteSize: number) => void
> = new Set();

maxBlobSize = 1024 * 1024 * 100; // 100MB
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@EYHN
Does it need to be changed to the default 10MB here?

@@ -48,6 +48,7 @@ export class Workspace extends Entity {
},
name: 'blob',
readonly: false,
maxFileSize: this.engine.blob.maxBlobSize,
Copy link
Member

Choose a reason for hiding this comment

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

i think this change is not good, because the maxBlobSize value will change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use a getter

@fundon fundon force-pushed the fundon/04_23_get_maxFileSize_from_blobSync branch from fe40ed2 to 862b16b Compare April 24, 2025 04:04
Copy link

coderabbitai bot commented Apr 24, 2025

Walkthrough

This change removes the FileSizeLimitService and its usage from the codebase, centralizing file size limit logic within the blob storage layer. All references to FileSizeLimitService are replaced with direct access to the maxFileSize property from the blob engine or blob sync store. The maximum file size constraint is now consistently sourced from the blob storage backend, and file size validation logic has been refactored for reuse. The BlobSource interface and related classes are updated to expose the file size limit, ensuring alignment between the frontend and backend constraints.

Changes

Files/Paths Change Summary
blocksuite/affine/shared/src/services/file-size-limit-service.ts, blocksuite/affine/shared/src/services/index.ts Removed the FileSizeLimitService class and its export, eliminating the legacy file size limit service.
blocksuite/affine/all/src/extensions/migrating-store.ts Removed import and usage of FileSizeLimitService from store extensions.
blocksuite/affine/blocks/attachment/src/attachment-block.ts, blocksuite/affine/blocks/attachment/src/embed.ts Updated file size limit retrieval to use this.std.store.blobSync.maxFileSize instead of FileSizeLimitService.
blocksuite/affine/blocks/attachment/src/utils.ts, blocksuite/affine/blocks/image/src/utils.ts Introduced a hasExceeded helper function to centralize file size validation and toast notification logic. Refactored related functions to use this helper, removing duplicated code and direct file size checks. Updated function signatures to use BlockStdScope and retrieve file size limits from the blob sync store.
blocksuite/affine/blocks/image/src/commands/insert-images.ts, blocksuite/affine/blocks/image/src/image-service.ts Removed FileSizeLimitService usage and updated function calls to use the new parameter structure and file size limit retrieval method.
blocksuite/framework/sync/src/blob/engine.ts Added a maxFileSize getter to the BlobEngine class, returning the file size limit from the main blob source or a default value.
blocksuite/framework/sync/src/blob/source.ts Added an optional maxFileSize property to the BlobSource interface.
packages/common/nbstore/src/frontend/blob.ts Changed maxBlobSize from a private to a public property in BlobFrontend for external access.
packages/frontend/core/src/modules/workspace/entities/workspace.ts Added a maxFileSize getter to the blob source object, sourcing the value from the workspace engine's blob service.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant BlockStdScope
    participant BlobSync
    participant BlobEngine
    participant BlobSource

    User->>UI: Uploads file(s)
    UI->>BlockStdScope: Handle file(s)
    BlockStdScope->>BlobSync: Access maxFileSize
    BlobSync->>BlobEngine: Get maxFileSize
    BlobEngine->>BlobSource: Get maxFileSize (if defined)
    BlobEngine-->>BlobSync: Return maxFileSize
    BlobSync-->>BlockStdScope: Return maxFileSize
    BlockStdScope->>UI: Validate file size(s)
    alt File size exceeded
        UI->>User: Show toast "File too large"
    else File size OK
        UI->>User: Proceed with upload
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure file size limit is consistent and sourced from blob storage backend (BS-3287)
Remove ineffective or redundant FileSizeLimitService (BS-3287)

Poem

A rabbit hopped through code today,
Cleaning up the size-check way.
No more services for file constraint—
The blob now rules, robust and quaint.
With helpers neat and logic clear,
Uploads are safe—no need to fear!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (4)
blocksuite/affine/blocks/attachment/src/utils.ts (2)

192-205: Consider extracting hasExceeded into a shared util to avoid duplication

A function with identical behaviour now exists in both attachment/src/utils.ts and image/src/utils.ts. Copy-pasting nudges technical-debt upward and increases the likelihood that the two implementations silently diverge in the future (e.g. wording of the toast, unit size precision, etc.).

-// local helper
-function hasExceeded(std: BlockStdScope, files: File[], maxFileSize = std.store.blobSync.maxFileSize) { ... }
+// utils/file-size.ts  (proposed new module)
+export function hasExceeded(
+  std: BlockStdScope,
+  files: File[],
+  maxFileSize: number = std.store.blobSync.maxFileSize
+) { ... }

Both image and attachment helpers could then import the single source of truth.


192-196: Default-parameter referencing a previous argument can be surprising

Using maxFileSize = std.store.blobSync.maxFileSize works, but the implicit ordering rule (defaults are evaluated left-to-right) is easy to forget, and ESLint/Biome usually flags it in larger codebases.

A more explicit pattern is often clearer:

function hasExceeded(std: BlockStdScope, files: File[], maxFileSize?: number) {
  maxFileSize ??= std.store.blobSync.maxFileSize;
  ...
}

This keeps the signature simple and avoids potential foot-guns if the parameter list is ever reordered.

blocksuite/affine/blocks/image/src/utils.ts (2)

312-325: Duplicate implementation – please DRY this helper

hasExceeded here is byte-for-byte the same as the one added to attachment/src/utils.ts. Re-exporting a single helper (e.g. from affine-shared/utils/file-size.ts) will:

  • Eliminate duplication
  • Guarantee consistent wording / behaviour
  • Simplify future maintenance (e.g. changing toast style or rounding rule)

450-451: Simplify unnecessary ternary

inTopLeft is already a boolean; the ternary can be replaced with a direct assignment to satisfy Biome’s no-useless-ternary lint and improve readability.

-const isMultipleFiles = files.length > 1;
-const inTopLeft = isMultipleFiles ? true : false;
+const isMultipleFiles = files.length > 1;
+const inTopLeft = isMultipleFiles;
🧰 Tools
🪛 Biome (1.9.4)

[error] 451-451: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2200bd7 and 862b16b.

📒 Files selected for processing (13)
  • blocksuite/affine/all/src/extensions/migrating-store.ts (0 hunks)
  • blocksuite/affine/blocks/attachment/src/attachment-block.ts (2 hunks)
  • blocksuite/affine/blocks/attachment/src/embed.ts (1 hunks)
  • blocksuite/affine/blocks/attachment/src/utils.ts (4 hunks)
  • blocksuite/affine/blocks/image/src/commands/insert-images.ts (1 hunks)
  • blocksuite/affine/blocks/image/src/image-service.ts (2 hunks)
  • blocksuite/affine/blocks/image/src/utils.ts (6 hunks)
  • blocksuite/affine/shared/src/services/file-size-limit-service.ts (0 hunks)
  • blocksuite/affine/shared/src/services/index.ts (0 hunks)
  • blocksuite/framework/sync/src/blob/engine.ts (2 hunks)
  • blocksuite/framework/sync/src/blob/source.ts (1 hunks)
  • packages/common/nbstore/src/frontend/blob.ts (1 hunks)
  • packages/frontend/core/src/modules/workspace/entities/workspace.ts (2 hunks)
💤 Files with no reviewable changes (3)
  • blocksuite/affine/all/src/extensions/migrating-store.ts
  • blocksuite/affine/shared/src/services/index.ts
  • blocksuite/affine/shared/src/services/file-size-limit-service.ts
🧰 Additional context used
🧬 Code Graph Analysis (3)
blocksuite/affine/blocks/image/src/image-service.ts (1)
blocksuite/affine/blocks/image/src/utils.ts (1)
  • addSiblingImageBlock (336-364)
blocksuite/affine/blocks/image/src/commands/insert-images.ts (1)
blocksuite/affine/blocks/image/src/utils.ts (1)
  • addSiblingImageBlock (336-364)
blocksuite/affine/blocks/attachment/src/utils.ts (2)
blocksuite/framework/sync/src/blob/engine.ts (1)
  • maxFileSize (110-112)
blocksuite/framework/std/src/gfx/index.ts (1)
  • GfxControllerIdentifier (17-17)
🪛 Biome (1.9.4)
blocksuite/affine/blocks/image/src/utils.ts

[error] 451-451: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (11)
blocksuite/affine/blocks/image/src/image-service.ts (2)

4-4: Clean import update

Removed the FileSizeLimitService import while retaining TelemetryProvider. This is consistent with the PR objective of removing the service dependency.


20-20: Function call properly updated

The call to addSiblingImageBlock has been correctly updated to:

  1. Pass std instead of std.host as the first argument
  2. Remove the now-unnecessary maxFileSize parameter

This aligns with the updated function signature in utils.ts which now uses hasExceeded(std, files) internally to check file size limits directly from the blob sync engine.

blocksuite/framework/sync/src/blob/engine.ts (2)

5-6: Good constant definition for default file size.

The addition of a clearly named constant with a comment accurately reflects the purpose of this default value (10MB) for local use. This follows best practices of avoiding magic numbers in code.


110-112: Well-implemented getter for maxFileSize.

This getter provides a clear, centralized approach to retrieving the maximum file size, with appropriate fallback to the default constant. It aligns with the PR objective of centralizing file size limit management in the blob engine.

packages/frontend/core/src/modules/workspace/entities/workspace.ts (2)

26-26: Appropriate helper function to encapsulate max file size access.

Good approach to create a function that encapsulates the retrieval of maxBlobSize from the engine, making the code more maintainable.


53-55: Well-implemented dynamic getter for maxFileSize.

The use of a getter here is excellent as it addresses the previously raised concern about maxBlobSize values changing. This implementation ensures the code always retrieves the current value rather than capturing a potentially stale value at initialization time.

blocksuite/affine/blocks/image/src/commands/insert-images.ts (1)

31-31: Good simplification of function call parameters.

The modified call to addSiblingImageBlock is cleaner and more maintainable. Passing the std object directly aligns with the PR objective of centralizing file size limit access through the blob engine rather than using a separate service.

blocksuite/framework/sync/src/blob/source.ts (1)

4-4: Good addition to the BlobSource interface

Adding the optional maxFileSize property to the BlobSource interface is appropriate and aligns well with the PR objective of centralizing file size limit management.

blocksuite/affine/blocks/attachment/src/embed.ts (1)

70-70: Correctly refactored to use centralized maxFileSize

The change to access maxFileSize directly from the blob sync engine instead of using the FileSizeLimitService is aligned with the PR objective of centralizing file size limit management.

blocksuite/affine/blocks/attachment/src/attachment-block.ts (2)

13-13: Removed FileSizeLimitService import correctly

The import list has been properly updated to remove the FileSizeLimitService while retaining ThemeProvider.


43-43: Correctly refactored to use centralized maxFileSize

The change to access maxFileSize directly from the blob sync engine instead of using the FileSizeLimitService is aligned with the PR objective of centralizing file size limit management.

private readonly onReachedMaxBlobSizeCallbacks: Set<
(byteSize: number) => void
> = new Set();

maxBlobSize = 1024 * 1024 * 100; // 100MB
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify default file size value consistency across the codebase.

The default maxBlobSize here is set to 100MB, while the fallback in BlobEngine is 10MB. Consider aligning these values to maintain consistency, or document the reason for the difference to avoid confusion.


🏁 Script executed:

#!/bin/bash
# Find all occurrences of file size constants in the codebase
echo "Searching for file size constants in the codebase..."
rg -i "max.*size|max.*blob|file.*size" --type ts -g "*.ts" | grep -E "([0-9]+\s*\*\s*1024|1024\s*\*\s*[0-9]+)"

Length of output: 723


Align or document file size limits

There are multiple file‐size thresholds in the codebase (100 MB, 50 MB and 10 MB). To avoid confusion, either extract these into shared constants or document why they differ:

• packages/common/nbstore/src/frontend/blob.ts
– maxBlobSize = 1024 * 1024 * 100 // 100 MB

• blocksuite/framework/sync/src/blob/engine.ts
– const MAX_FILE_SIZE = 10 * 1024 * 1024 // 10 MB

• packages/frontend/media-capture-playground/server/main.ts
– fileSize: 50 * 1024 * 1024 // 50 MB

• packages/frontend/core/src/blocksuite/ai/components/ai-chat-chips/add-popover.ts
– if (file.size > 50 * 1024 * 1024) { … }

Options:

  1. Define shared constants (e.g. TOTAL_BLOB_LIMIT, CHUNK_SIZE_LIMIT) and import them where needed.
  2. If these serve different purposes (total upload vs. sync chunk vs. UI filter), add comments or update docs to clarify each limit’s intent.

@fundon fundon force-pushed the fundon/04_23_get_maxFileSize_from_blobSync branch from 862b16b to ece22e1 Compare April 24, 2025 11:37
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: 0

🧹 Nitpick comments (1)
blocksuite/affine/blocks/image/src/utils.ts (1)

451-452: Simplify boolean expression.

The ternary operator here is unnecessary since isMultipleFiles is already a boolean.

const isMultipleFiles = files.length > 1;
-const inTopLeft = isMultipleFiles ? true : false;
+const inTopLeft = isMultipleFiles;
🧰 Tools
🪛 Biome (1.9.4)

[error] 451-451: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 862b16b and ece22e1.

📒 Files selected for processing (13)
  • blocksuite/affine/all/src/extensions/migrating-store.ts (0 hunks)
  • blocksuite/affine/blocks/attachment/src/attachment-block.ts (2 hunks)
  • blocksuite/affine/blocks/attachment/src/embed.ts (1 hunks)
  • blocksuite/affine/blocks/attachment/src/utils.ts (4 hunks)
  • blocksuite/affine/blocks/image/src/commands/insert-images.ts (1 hunks)
  • blocksuite/affine/blocks/image/src/image-service.ts (2 hunks)
  • blocksuite/affine/blocks/image/src/utils.ts (6 hunks)
  • blocksuite/affine/shared/src/services/file-size-limit-service.ts (0 hunks)
  • blocksuite/affine/shared/src/services/index.ts (0 hunks)
  • blocksuite/framework/sync/src/blob/engine.ts (2 hunks)
  • blocksuite/framework/sync/src/blob/source.ts (1 hunks)
  • packages/common/nbstore/src/frontend/blob.ts (1 hunks)
  • packages/frontend/core/src/modules/workspace/entities/workspace.ts (2 hunks)
💤 Files with no reviewable changes (3)
  • blocksuite/affine/all/src/extensions/migrating-store.ts
  • blocksuite/affine/shared/src/services/index.ts
  • blocksuite/affine/shared/src/services/file-size-limit-service.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/frontend/core/src/modules/workspace/entities/workspace.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • blocksuite/framework/sync/src/blob/source.ts
  • blocksuite/affine/blocks/attachment/src/embed.ts
  • blocksuite/framework/sync/src/blob/engine.ts
  • blocksuite/affine/blocks/image/src/image-service.ts
  • blocksuite/affine/blocks/attachment/src/attachment-block.ts
  • blocksuite/affine/blocks/image/src/commands/insert-images.ts
  • packages/common/nbstore/src/frontend/blob.ts
  • blocksuite/affine/blocks/attachment/src/utils.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
blocksuite/affine/blocks/image/src/utils.ts (2)
blocksuite/framework/sync/src/blob/engine.ts (1)
  • maxFileSize (110-112)
blocksuite/framework/std/src/gfx/index.ts (1)
  • GfxControllerIdentifier (17-17)
🪛 Biome (1.9.4)
blocksuite/affine/blocks/image/src/utils.ts

[error] 451-451: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (10)
blocksuite/affine/blocks/image/src/utils.ts (10)

8-8: Simplified import structure.

The removal of FileSizeLimitService import aligns with the PR's goal of centralizing file size limit logic within the blob storage layer.


312-325: Good abstraction of file size validation logic.

The new hasExceeded helper function effectively centralizes file size validation that was likely duplicated across multiple functions. It provides a consistent way to check file sizes against limits and display user-friendly error messages.


337-338: Consistent parameter replacement across functions.

The change from editorHost to std: BlockStdScope provides a more comprehensive access point to the editor's components, aligning with the codebase's architecture.

Also applies to: 367-368, 424-425


342-345: Improved function flow with early returns and validation.

The refactoring improves code efficiency by:

  1. Filtering files to only include images
  2. Returning early if no valid files exist
  3. Using the new hasExceeded function to validate file sizes
  4. Aborting if files exceed size limits

This approach reduces unnecessary processing and improves code readability.


355-359: Updated API usage to match new parameter structure.

The code now correctly uses std.store methods instead of editorHost.doc and passes std.host instead of editorHost to the upload function, maintaining consistency with the parameter changes.

Also applies to: 361-362


372-375: Consistent validation pattern applied.

The same pattern of filtering files and early validation is appropriately applied here, ensuring consistency across similar functions.


377-382: Updated block creation and upload logic.

Block creation now properly uses std.store methods, and the upload function receives the correct host parameter.


432-438: Optimized processing order in addImages.

The function now filters files and validates file sizes before retrieving the graphics controller, which is more efficient as it avoids unnecessary operations when validation fails.


454-458: Consistent use of filtered files array.

The code now correctly iterates through the filtered files array, ensuring that only valid image files are processed for upload.


474-508: Proper file processing with error handling.

The image upload and block update logic correctly handles errors, validates image dimensions, and updates the model with appropriate values. The function now uses std.store methods consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants