mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 23:21:08 +10:00
feat: editor file attachments (#194)
* fix current slider value * WIP * changes to extension attributes * update command title
This commit is contained in:
@ -30,7 +30,7 @@ export function getAvatarUrl(avatarUrl: string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (avatarUrl.startsWith("http")) {
|
||||
if (avatarUrl?.startsWith("http")) {
|
||||
return avatarUrl;
|
||||
}
|
||||
|
||||
@ -42,5 +42,5 @@ export function getSpaceUrl(spaceSlug: string) {
|
||||
}
|
||||
|
||||
export function getFileUrl(src: string) {
|
||||
return src.startsWith("/files/") ? getBackendUrl() + src : src;
|
||||
return src?.startsWith("/files/") ? getBackendUrl() + src : src;
|
||||
}
|
||||
|
||||
@ -25,3 +25,22 @@ export const computeSpaceSlug = (name: string) => {
|
||||
return alphanumericName.toLowerCase();
|
||||
}
|
||||
};
|
||||
|
||||
export const formatBytes = (
|
||||
bytes: number,
|
||||
decimalPlaces: number = 2,
|
||||
): 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;
|
||||
|
||||
const unitIndex = Math.floor(Math.log(kilobytes) / Math.log(unitSize));
|
||||
const adjustedUnitIndex = Math.max(unitIndex, 0);
|
||||
const adjustedSize = kilobytes / Math.pow(unitSize, adjustedUnitIndex);
|
||||
|
||||
return `${adjustedSize.toFixed(precision)} ${units[adjustedUnitIndex]}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user