fix(editor): unify file size formatting method (#12444)

Closes: [BS-3524](https://linear.app/affine-design/issue/BS-3524/统一文件大小单位,与-af-一致)

![Screenshot 2025-05-22 at 15.09.41.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/8ypiIKZXudF5a0tIgIzf/ddb6fa38-243f-4e65-b572-d476e3771d74.png)

![Screenshot 2025-05-22 at 15.09.48.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/8ypiIKZXudF5a0tIgIzf/5d182332-4d0a-419a-b206-df58552fe740.png)

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

- **Refactor**
  - Updated file size formatting throughout the app to use a new, consistent utility for displaying file sizes.
  - Improved clarity and uniformity of file size information in attachments, images, and related notifications.
  - Enhanced type support to explicitly allow null values for file size descriptions.
- **Bug Fixes**
  - Adjusted file size display in tests to match updated formatting standards.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fundon
2025-05-23 06:33:30 +00:00
parent fd3a2756f8
commit d0539fde22
12 changed files with 21 additions and 52 deletions
@@ -1,7 +1,7 @@
import { getAttachmentFileIcon } from '@blocksuite/affine/components/icons';
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
import { humanFileSize } from '@blocksuite/affine-shared/utils';
import { formatSize } from '@blocksuite/affine-shared/utils';
import {
ArrowDownBigIcon,
ArrowUpBigIcon,
@@ -18,7 +18,7 @@ const DPI = window.devicePixelRatio;
type FileInfo = {
name: string;
size: string;
size: string | null;
isPDF: boolean;
icon: TemplateResult;
};
@@ -161,7 +161,7 @@ export class AttachmentViewerPanel extends SignalWatcher(
name,
icon,
isPDF,
size: humanFileSize(size),
size: formatSize(size),
};
if (!isPDF) return;