mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 21:41:52 +08:00
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:
@@ -11,11 +11,16 @@ import {
|
||||
AttachmentBlockStyles,
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
FileSizeLimitService,
|
||||
FileSizeLimitProvider,
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { humanFileSize } from '@blocksuite/affine-shared/utils';
|
||||
import { AttachmentIcon, ResetIcon, WarningIcon } from '@blocksuite/icons/lit';
|
||||
import {
|
||||
AttachmentIcon,
|
||||
ResetIcon,
|
||||
UpgradeIcon,
|
||||
WarningIcon,
|
||||
} from '@blocksuite/icons/lit';
|
||||
import { BlockSelection } from '@blocksuite/std';
|
||||
import { Slice } from '@blocksuite/store';
|
||||
import { type BlobState } from '@blocksuite/sync';
|
||||
@@ -50,7 +55,7 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
||||
});
|
||||
|
||||
private get _maxFileSize() {
|
||||
return this.std.store.get(FileSizeLimitService).maxFileSize;
|
||||
return this.std.get(FileSizeLimitProvider).maxFileSize;
|
||||
}
|
||||
|
||||
get isCitation() {
|
||||
@@ -185,7 +190,24 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
||||
}
|
||||
|
||||
protected renderUpgradeButton = () => {
|
||||
return null;
|
||||
if (this.std.store.readonly) return null;
|
||||
|
||||
const onOverFileSize = this.std.get(FileSizeLimitProvider).onOverFileSize;
|
||||
|
||||
return when(
|
||||
onOverFileSize,
|
||||
() => html`
|
||||
<button
|
||||
class="affine-attachment-content-button"
|
||||
@click=${(event: MouseEvent) => {
|
||||
event.stopPropagation();
|
||||
onOverFileSize?.();
|
||||
}}
|
||||
>
|
||||
${UpgradeIcon()} Upgrade
|
||||
</button>
|
||||
`
|
||||
);
|
||||
};
|
||||
|
||||
protected renderReloadButton = () => {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
type ImageBlockProps,
|
||||
MAX_IMAGE_WIDTH,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { FileSizeLimitService } from '@blocksuite/affine-shared/services';
|
||||
import { FileSizeLimitProvider } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
readImageSize,
|
||||
transformModel,
|
||||
@@ -68,7 +68,7 @@ export const AttachmentEmbedProvider = createIdentifier<AttachmentEmbedService>(
|
||||
|
||||
export class AttachmentEmbedService extends Extension {
|
||||
private get _maxFileSize() {
|
||||
return this.std.store.get(FileSizeLimitService).maxFileSize;
|
||||
return this.std.get(FileSizeLimitProvider).maxFileSize;
|
||||
}
|
||||
|
||||
get keys() {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
type AttachmentUploadedEvent,
|
||||
FileSizeLimitService,
|
||||
FileSizeLimitProvider,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { humanFileSize } from '@blocksuite/affine-shared/utils';
|
||||
@@ -110,7 +110,7 @@ export async function getFileType(file: File) {
|
||||
function hasExceeded(
|
||||
std: BlockStdScope,
|
||||
files: File[],
|
||||
maxFileSize = std.store.get(FileSizeLimitService).maxFileSize
|
||||
maxFileSize = std.get(FileSizeLimitProvider).maxFileSize
|
||||
) {
|
||||
const exceeded = files.some(file => file.size > maxFileSize);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user