0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-22 01:22:32 -05:00

fix: wrong validation for expiration in reverse share modal

This commit is contained in:
Elias Schneider 2025-01-04 01:27:59 +01:00
parent 4a7076a094
commit b3ea96c191
No known key found for this signature in database
GPG key ID: 07E623B294202B6C
2 changed files with 16 additions and 9 deletions

View file

@ -26,10 +26,11 @@ export class ReverseShareService {
.toDate();
const parsedExpiration = parseRelativeDateToAbsolute(data.shareExpiration);
const maxExpiration = this.config.get("share.maxExpiration");
if (
this.config.get("share.maxExpiration") !== 0 &&
maxExpiration.value !== 0 &&
parsedExpiration >
moment().add(this.config.get("share.maxExpiration"), "hours").toDate()
moment().add(maxExpiration.value, maxExpiration.unit).toDate()
) {
throw new BadRequestException(
"Expiration date exceeds maximum expiration date",

View file

@ -20,6 +20,7 @@ import useTranslate, {
translateOutsideContext,
} from "../../../hooks/useTranslate.hook";
import shareService from "../../../services/share.service";
import { Timespan } from "../../../types/timespan.type";
import { getExpirationPreview } from "../../../utils/date.util";
import toast from "../../../utils/toast.util";
import FileSizeInput from "../../core/FileSizeInput";
@ -28,7 +29,7 @@ import showCompletedReverseShareModal from "./showCompletedReverseShareModal";
const showCreateReverseShareModal = (
modals: ModalsContextProps,
showSendEmailNotificationOption: boolean,
maxExpirationInHours: number,
maxExpiration: Timespan,
getReverseShares: () => void,
) => {
const t = translateOutsideContext();
@ -38,7 +39,7 @@ const showCreateReverseShareModal = (
<Body
showSendEmailNotificationOption={showSendEmailNotificationOption}
getReverseShares={getReverseShares}
maxExpirationInHours={maxExpirationInHours}
maxExpiration={maxExpiration}
/>
),
});
@ -47,12 +48,13 @@ const showCreateReverseShareModal = (
const Body = ({
getReverseShares,
showSendEmailNotificationOption,
maxExpirationInHours,
maxExpiration,
}: {
getReverseShares: () => void;
showSendEmailNotificationOption: boolean;
maxExpirationInHours: number;
maxExpiration: Timespan;
}) => {
console.log(maxExpiration);
const modals = useModals();
const t = useTranslate();
@ -91,13 +93,17 @@ const Body = ({
) as moment.unitOfTime.DurationConstructor,
);
if (
maxExpirationInHours != 0 &&
expirationDate.isAfter(moment().add(maxExpirationInHours, "hours"))
maxExpiration.value != 0 &&
expirationDate.isAfter(
moment().add(maxExpiration.value, maxExpiration.unit),
)
) {
form.setFieldError(
"expiration_num",
t("upload.modal.expires.error.too-long", {
max: moment.duration(maxExpirationInHours, "hours").humanize(),
max: moment
.duration(maxExpiration.value, maxExpiration.unit)
.humanize(),
}),
);
return;