refactor(editor): file size limit service (#12026)

Closes: [BS-3359](https://linear.app/affine-design/issue/BS-3359/重构-filesizelimitservice-支持-handle-文件超出限制)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added an "Upgrade" button to attachment blocks that appears when file size limits are exceeded, enabling users to view storage plans and upgrade.

- **Refactor**
  - Unified file size limit handling across attachments and images for consistency.
  - Redesigned file size limit service with improved integration and dependency injection.

- **Chores**
  - Updated service registrations and dependency management for file size limit enforcement.
  - Integrated a new file size limit extension that triggers storage plan dialogs and tracking events on limit exceedance.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fundon
2025-04-29 08:05:28 +00:00
parent 7e4af90c03
commit 0f87136fd7
9 changed files with 92 additions and 20 deletions

View File

@@ -1,10 +1,23 @@
import { StoreExtension } from '@blocksuite/store';
import { type Container, createIdentifier } from '@blocksuite/global/di';
import { Extension } from '@blocksuite/store';
// bytes.parse('2GB')
const maxFileSize = 2 * 1024 * 1024 * 1024;
export class FileSizeLimitService extends StoreExtension {
static override key = 'file-size-limit';
maxFileSize = maxFileSize;
export interface IFileSizeLimitService {
maxFileSize: number;
onOverFileSize?: () => void;
}
export const FileSizeLimitProvider = createIdentifier<IFileSizeLimitService>(
'FileSizeLimitService'
);
export class FileSizeLimitService
extends Extension
implements IFileSizeLimitService
{
// 2GB
maxFileSize = 2 * 1024 * 1024 * 1024;
static override setup(di: Container) {
di.addImpl(FileSizeLimitProvider, FileSizeLimitService);
}
}