1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Adding never expiring sharing link. #260

It works by setting the expirity to -1 that setts the expire dat to 01/01/9999. Now the UI does not show expiration if it is longer than 10 years
This commit is contained in:
Patrik J. Braun 2021-04-19 15:56:50 +02:00
parent 07012ebd3c
commit 4af6c16aef
13 changed files with 76 additions and 29 deletions

View File

@ -55,7 +55,9 @@ export class SharingMWs {
path: directoryName,
password: createSharing.password,
creator: req.session.user,
expires: Date.now() + createSharing.valid,
expires: createSharing.valid >= 0 ? // if === -1 its forever
Date.now() + createSharing.valid :
(new Date(9999, 0, 1)).getTime(), // never expire
includeSubfolders: createSharing.includeSubfolders,
timeStamp: Date.now()
};
@ -86,7 +88,9 @@ export class SharingMWs {
sharingKey: '',
password: (updateSharing.password && updateSharing.password !== '') ? updateSharing.password : null,
creator: req.session.user,
expires: Date.now() + updateSharing.valid,
expires: updateSharing.valid >= 0 // if === -1 its forever
? Date.now() + updateSharing.valid :
(new Date(9999, 0, 1)).getTime(), // never expire
includeSubfolders: updateSharing.includeSubfolders,
timeStamp: Date.now()
};

View File

@ -60,6 +60,11 @@ export class GalleryComponent implements OnInit, OnDestroy {
if (this.shareService.sharingSubject.value == null) {
return;
}
// if the timer is longer than 10 years, just do not show it
if ((this.shareService.sharingSubject.value.expires - Date.now()) / 1000 / 86400 / 365 > 10) {
return;
}
t = Math.floor((this.shareService.sharingSubject.value.expires - Date.now()) / 1000);
this.countDown = ({} as any);
this.countDown.day = Math.floor(t / 86400);
@ -132,7 +137,7 @@ export class GalleryComponent implements OnInit, OnDestroy {
directoryName = directoryName || '';
this.galleryService.loadDirectory(directoryName);
}
};
private onContentChange = (content: ContentWrapper): void => {
const tmp = (content.searchResult || content.directory || {
@ -153,7 +158,7 @@ export class GalleryComponent implements OnInit, OnDestroy {
break;
}
}
}
};
private sortDirectories(): void {
if (!this.directories) {

View File

@ -71,7 +71,8 @@
<div class="row">
<div class="col-4">
<label class="control-label" for="share-password">
<ng-container i18n>Password</ng-container>*:
<ng-container i18n>Password</ng-container>
*:
</label>
</div>
<div class="col-8" *ngIf="passwordProtection">
@ -95,7 +96,8 @@
<input class="form-control" [(ngModel)]="input.valid.amount" (change)="update()"
name="valid-from"
id="valid-from"
type="number" min="0" step="1"/>
[disabled]="input.valid.type === ValidityTypes.Forever"
type="number" min="1" step="1"/>
</div>
<div class="col-4" style="padding-left: 1px">
<select class="form-control"
@ -105,6 +107,7 @@
<option [ngValue]="ValidityTypes.Hours" i18n>Hours</option>
<option [ngValue]="ValidityTypes.Days" i18n>Days</option>
<option [ngValue]="ValidityTypes.Months" i18n>Months</option>
<option [ngValue]="ValidityTypes.Forever" i18n>Forever</option>
</select>
</div>
</div>

View File

@ -26,7 +26,7 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
includeSubfolders: true,
valid: {
amount: 30,
type: ValidityTypes.Days
type: ValidityTypes.Days as ValidityTypes
},
password: null as string
};
@ -79,6 +79,8 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
return this.input.valid.amount * 1000 * 60 * 60 * 24;
case ValidityTypes.Months:
return this.input.valid.amount * 1000 * 60 * 60 * 24 * 30;
case ValidityTypes.Forever:
return -1;
}
throw new Error('unknown type: ' + this.input.valid.type);
}
@ -124,5 +126,5 @@ export class GalleryShareComponent implements OnInit, OnDestroy {
export enum ValidityTypes {
Minutes = 1, Hours = 2, Days = 3, Months = 4
Minutes = 1, Hours = 2, Days = 3, Months = 4, Forever = 99
}

View File

@ -32,7 +32,8 @@ export class ShareLoginComponent implements OnInit {
await this.authService.shareLogin(this.password);
} catch (error) {
if (error && error.code === ErrorCodes.CREDENTIAL_NOT_FOUND) {
if (error && error.code === ErrorCodes.CREDENTIAL_NOT_FOUND ||
error === 'Unauthorized') {
this.loginError = true;
}
}

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Örökké</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -2732,6 +2732,10 @@
<source>User creation error!</source>
<target>User creation error!</target>
</trans-unit>
<trans-unit id="233324084168950985" datatype="html">
<source>Forever</source>
<target>Forever</target>
</trans-unit>
</body>
</file>
</xliff>