feat: editor file attachments (#194)

* fix current slider value

* WIP

* changes to extension attributes

* update command title
This commit is contained in:
Philip Okugbe
2024-08-26 12:38:47 +01:00
committed by GitHub
parent 7e80797e3f
commit 7dc37b933f
19 changed files with 450 additions and 16 deletions

View File

@ -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;
}

View File

@ -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]}`;
};