mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 16:41:10 +10:00
fix translation
* fix filesize formatting
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { formatDistanceStrict } from "date-fns";
|
||||
import { format, isToday, isYesterday } from "date-fns";
|
||||
import i18n from "i18next";
|
||||
import i18n from "@/i18n.ts";
|
||||
|
||||
export function timeAgo(date: Date) {
|
||||
return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true });
|
||||
|
||||
@ -28,14 +28,10 @@ export const computeSpaceSlug = (name: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const formatBytes = (
|
||||
bytes: number,
|
||||
decimalPlaces: number = 2,
|
||||
): string => {
|
||||
export const formatBytes = (bytes: number): string => {
|
||||
if (bytes === 0) return "0.0 KB";
|
||||
|
||||
const unitSize = 1024;
|
||||
const precision = decimalPlaces < 0 ? 0 : decimalPlaces;
|
||||
const units = ["KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
|
||||
const kilobytes = bytes / unitSize;
|
||||
@ -44,6 +40,9 @@ export const formatBytes = (
|
||||
const adjustedUnitIndex = Math.max(unitIndex, 0);
|
||||
const adjustedSize = kilobytes / Math.pow(unitSize, adjustedUnitIndex);
|
||||
|
||||
// Use one decimal for KB and no decimals for MB or higher
|
||||
const precision = adjustedUnitIndex === 0 ? 1 : 0;
|
||||
|
||||
return `${adjustedSize.toFixed(precision)} ${units[adjustedUnitIndex]}`;
|
||||
};
|
||||
|
||||
@ -66,9 +65,9 @@ function decodeBase64(base64: string): string {
|
||||
}
|
||||
|
||||
export function decodeBase64ToSvgString(base64Data: string): string {
|
||||
const base64Prefix = 'data:image/svg+xml;base64,';
|
||||
const base64Prefix = "data:image/svg+xml;base64,";
|
||||
if (base64Data.startsWith(base64Prefix)) {
|
||||
base64Data = base64Data.replace(base64Prefix, '');
|
||||
base64Data = base64Data.replace(base64Prefix, "");
|
||||
}
|
||||
|
||||
return decodeBase64(base64Data);
|
||||
|
||||
Reference in New Issue
Block a user