fix(core): image block size limits were not enforced as expected (#8908)

This commit is contained in:
JimmFly 2024-11-25 07:15:14 +00:00
parent 08ff619d47
commit 4ce8a180aa
No known key found for this signature in database
GPG Key ID: 126E0320FEB0D05C

View File

@ -7,6 +7,7 @@ import {
import {
AttachmentBlockService,
AttachmentBlockSpec,
ImageBlockService,
} from '@blocksuite/affine/blocks';
import bytes from 'bytes';
@ -19,6 +20,15 @@ class CustomAttachmentBlockService extends AttachmentBlockService {
}
}
class CustomImageBlockService extends ImageBlockService {
override mounted(): void {
// blocksuite default max file size is 10MB, we override it to 2GB
// but the real place to limit blob size is CloudQuotaModal / LocalQuotaModal
this.maxFileSize = bytes.parse('2GB');
super.mounted();
}
}
export const CustomAttachmentBlockSpec: ExtensionType[] = [
...AttachmentBlockSpec,
{
@ -28,6 +38,11 @@ export const CustomAttachmentBlockSpec: ExtensionType[] = [
CustomAttachmentBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:attachment')]
);
di.override(
BlockServiceIdentifier('affine:image'),
CustomImageBlockService,
[StdIdentifier, BlockFlavourIdentifier('affine:image')]
);
},
},
];