feat: reverse shares (#86)
* add first concept * add reverse share funcionality to frontend * allow creator to limit share expiration * moved reverse share in seperate module * add table to manage reverse shares * delete complete share if reverse share was deleted * optimize function names * add db migration * enable reverse share email notifications * fix config variable descriptions * fix migration for new installations
This commit is contained in:
23
frontend/src/utils/fileSize.util.ts
Normal file
23
frontend/src/utils/fileSize.util.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export function byteToHumanSizeString(bytes: number) {
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
||||
if (bytes == 0) return "0 Byte";
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
|
||||
return (bytes / Math.pow(1024, i)).toFixed(1).toString() + " " + sizes[i];
|
||||
}
|
||||
|
||||
export function byteToUnitAndSize(bytes: number) {
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
if (bytes == 0) return { unit: "B", size: 0 };
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
|
||||
|
||||
return {
|
||||
size: parseFloat((bytes / Math.pow(1024, i)).toFixed(1)),
|
||||
unit: units[i],
|
||||
};
|
||||
}
|
||||
|
||||
export function unitAndSizeToByte(unit: string, size: number) {
|
||||
const units = ["B", "KB", "MB", "GB", "TB"];
|
||||
const i = units.indexOf(unit);
|
||||
return Math.pow(1024, i) * size;
|
||||
}
|
||||
Reference in New Issue
Block a user