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:
Elias Schneider
2023-01-26 13:44:04 +01:00
committed by GitHub
parent 1ceb07b89e
commit 4a5fb549c6
43 changed files with 1456 additions and 280 deletions

View File

@@ -0,0 +1,26 @@
import moment from "moment";
export const getExpirationPreview = (
name: string,
form: {
values: {
never_expires?: boolean;
expiration_num: number;
expiration_unit: string;
};
}
) => {
const value = form.values.never_expires
? "never"
: form.values.expiration_num + form.values.expiration_unit;
if (value === "never") return `This ${name} will never expire.`;
const expirationDate = moment()
.add(
value.split("-")[0],
value.split("-")[1] as moment.unitOfTime.DurationConstructor
)
.toDate();
return `This ${name} will expire on ${moment(expirationDate).format("LLL")}`;
};

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

View File

@@ -1,11 +0,0 @@
export function byteStringToHumanSizeString(bytes: string) {
const bytesNumber = parseInt(bytes);
const sizes = ["B", "KB", "MB", "GB", "TB"];
if (bytesNumber == 0) return "0 Byte";
const i = parseInt(
Math.floor(Math.log(bytesNumber) / Math.log(1024)).toString()
);
return (
(bytesNumber / Math.pow(1024, i)).toFixed(1).toString() + " " + sizes[i]
);
}