Refine storage file size reporting
This commit is contained in:
parent
2b9d12d43d
commit
3e0f2202d3
@ -6,6 +6,7 @@ import {
|
||||
PutObjectCommand,
|
||||
} from '@aws-sdk/client-s3';
|
||||
import { StorageListResponse, generateStorageId } from '.';
|
||||
import { formatBytesToMB } from '@/utility/number';
|
||||
|
||||
const AWS_S3_BUCKET = process.env.NEXT_PUBLIC_AWS_S3_BUCKET ?? '';
|
||||
const AWS_S3_REGION = process.env.NEXT_PUBLIC_AWS_S3_REGION ?? '';
|
||||
@ -74,7 +75,7 @@ export const awsS3List = async (
|
||||
url: urlForKey(Key),
|
||||
fileName: Key ?? '',
|
||||
uploadedAt: LastModified,
|
||||
size: Size ? `${Size.toFixed(2)}MB` : undefined,
|
||||
size: Size ? formatBytesToMB(Size) : undefined,
|
||||
})) ?? []);
|
||||
|
||||
export const awsS3Delete = async (Key: string) => {
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
} from '@aws-sdk/client-s3';
|
||||
import { StorageListResponse, generateStorageId } from '.';
|
||||
import { removeUrlProtocol } from '@/utility/url';
|
||||
import { formatBytesToMB } from '@/utility/number';
|
||||
|
||||
const CLOUDFLARE_R2_BUCKET =
|
||||
process.env.NEXT_PUBLIC_CLOUDFLARE_R2_BUCKET ?? '';
|
||||
@ -94,7 +95,7 @@ export const cloudflareR2List = async (
|
||||
url: urlForKey(Key),
|
||||
fileName: Key ?? '',
|
||||
uploadedAt: LastModified,
|
||||
size: Size ? `${Size.toFixed(2)}MB` : undefined,
|
||||
size: Size ? formatBytesToMB(Size) : undefined,
|
||||
})) ?? []);
|
||||
|
||||
export const cloudflareR2Delete = async (Key: string) => {
|
||||
|
||||
@ -85,5 +85,9 @@ export const formatNumberToFraction = (number: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const formatBytesToMB = (bytes: number) =>
|
||||
`${(bytes / 1024 / 1024).toFixed(2)}MB`;
|
||||
export const formatBytesToMB = (
|
||||
bytes: number,
|
||||
byteSize = 1000,
|
||||
precision = 1,
|
||||
) =>
|
||||
`${(bytes / byteSize / byteSize).toFixed(precision)}MB`;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user