1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-16 12:20:13 +01:00

fix: max expiration gets ignored if expiration is set to "never"

This commit is contained in:
Elias Schneider 2023-11-17 15:27:22 +01:00
parent 2e1a2b60c4
commit 330eef51e4
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C
4 changed files with 13 additions and 7 deletions

View File

@ -19,7 +19,6 @@ export class ShareOwnerGuard extends JwtGuard {
} }
async canActivate(context: ExecutionContext) { async canActivate(context: ExecutionContext) {
const request: Request = context.switchToHttp().getRequest(); const request: Request = context.switchToHttp().getRequest();
const shareId = Object.prototype.hasOwnProperty.call( const shareId = Object.prototype.hasOwnProperty.call(
request.params, request.params,

View File

@ -54,10 +54,15 @@ export class ShareService {
} else { } else {
const parsedExpiration = parseRelativeDateToAbsolute(share.expiration); const parsedExpiration = parseRelativeDateToAbsolute(share.expiration);
const expiresNever = moment(0).toDate() == parsedExpiration;
if ( if (
this.config.get("share.maxExpiration") !== 0 && this.config.get("share.maxExpiration") !== 0 &&
(expiresNever ||
parsedExpiration > parsedExpiration >
moment().add(this.config.get("share.maxExpiration"), "hours").toDate() moment()
.add(this.config.get("share.maxExpiration"), "hours")
.toDate())
) { ) {
throw new BadRequestException( throw new BadRequestException(
"Expiration date exceeds maximum expiration date", "Expiration date exceeds maximum expiration date",

View File

@ -12,7 +12,7 @@ const showShareInformationsModal = (
modals: ModalsContextProps, modals: ModalsContextProps,
share: MyShare, share: MyShare,
appUrl: string, appUrl: string,
maxShareSize: number maxShareSize: number,
) => { ) => {
const t = translateOutsideContext(); const t = translateOutsideContext();
const link = `${appUrl}/s/${share.id}`; const link = `${appUrl}/s/${share.id}`;

View File

@ -125,11 +125,13 @@ const CreateUploadModalBody = ({
"", "",
) as moment.unitOfTime.DurationConstructor, ) as moment.unitOfTime.DurationConstructor,
); );
if ( if (
options.maxExpirationInHours != 0 && options.maxExpirationInHours != 0 &&
(form.values.never_expires ||
expirationDate.isAfter( expirationDate.isAfter(
moment().add(options.maxExpirationInHours, "hours"), moment().add(options.maxExpirationInHours, "hours"),
) ))
) { ) {
form.setFieldError( form.setFieldError(
"expiration_num", "expiration_num",