fix: Handle missing size on attachment
This commit is contained in:
@@ -9,5 +9,6 @@ describe("bytesToHumanReadable", () => {
|
|||||||
expect(bytesToHumanReadable(12345)).toBe("12.34 kB");
|
expect(bytesToHumanReadable(12345)).toBe("12.34 kB");
|
||||||
expect(bytesToHumanReadable(123456)).toBe("123.45 kB");
|
expect(bytesToHumanReadable(123456)).toBe("123.45 kB");
|
||||||
expect(bytesToHumanReadable(1234567)).toBe("1.23 MB");
|
expect(bytesToHumanReadable(1234567)).toBe("1.23 MB");
|
||||||
|
expect(bytesToHumanReadable(undefined)).toBe("0 Bytes");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
* @param bytes filesize in bytes
|
* @param bytes filesize in bytes
|
||||||
* @returns Human readable filesize as a string
|
* @returns Human readable filesize as a string
|
||||||
*/
|
*/
|
||||||
export function bytesToHumanReadable(bytes: number) {
|
export function bytesToHumanReadable(bytes: number | undefined) {
|
||||||
|
if (!bytes) {
|
||||||
|
return "0 Bytes";
|
||||||
|
}
|
||||||
|
|
||||||
const out = ("0".repeat((bytes.toString().length * 2) % 3) + bytes).match(
|
const out = ("0".repeat((bytes.toString().length * 2) % 3) + bytes).match(
|
||||||
/.{3}/g
|
/.{3}/g
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user