Adding infinite expiration time

This commit is contained in:
Axel 2023-07-07 10:42:03 +02:00
parent 3504b0a6ca
commit 5d617d649c
Signed by: axel
GPG key ID: 73C0A5961B6BC740
7 changed files with 61 additions and 31 deletions

View file

@ -136,7 +136,14 @@ class UploadController extends Controller
// Saving metadata
try {
$bundle->completed = true;
$bundle->expires_at = time()+$bundle->expiry;
// Infinite expiry
if ($bundle->expiry == 'forever') {
$bundle->expires_at = null;
}
else {
$bundle->expires_at = time()+$bundle->expiry;
}
$bundle->fullsize = $size;
$bundle->preview_link = route('bundle.preview', ['bundle' => $bundle, 'auth' => $bundle->preview_token]);
$bundle->download_link = route('bundle.zip.download', ['bundle' => $bundle, 'auth' => $bundle->preview_token]);
@ -171,7 +178,12 @@ class UploadController extends Controller
$f->forceDelete();
}
return response()->json(new BundleResource($bundle));
// Finally deleting bundle
$bundle->forceDelete();
return response()->json([
'success' => true
]);
}
catch (Exception $e) {
return response()->json([

View file

@ -30,7 +30,9 @@ class GuestAccess
abort_if($bundle->preview_token !== $request->auth, 403);
// Aborting if bundle expired
abort_if($bundle->expires_at->isBefore(Carbon::now()), 404);
if (! empty($bundle->expires_at)) {
abort_if($bundle->expires_at->isBefore(Carbon::now()), 404);
}
// Aborting if max download is reached
abort_if( ($bundle->max_downloads ?? 0) > 0 && $bundle->downloads >= $bundle->max_downloads, 404);

View file

@ -5,17 +5,17 @@ return [
'max_filesize' => env('UPLOAD_MAX_FILESIZE', '5M'),
'max_files' => env('UPLOAD_MAX_FILES', 100),
'expiry_values' => [
'1H' => 'one-hour',
'2H' => 'two-hours',
'6H' => 'six-hours',
'12H' => 'twelve-hours',
'24H' => 'one-day',
'48H' => 'two-days',
'1W' => 'one-week',
'2W' => 'two-weeks',
'1M' => 'one-month',
'3M' => 'three-months',
'6M' => 'six-months'
'1H' => 'one-hour',
'2H' => 'two-hours',
'6H' => 'six-hours',
'12H' => 'twelve-hours',
'24H' => 'one-day',
'48H' => 'two-days',
'1W' => 'one-week',
'2W' => 'two-weeks',
'1M' => 'one-month',
'3M' => 'three-months',
'6M' => 'six-months',
],
'default_expiry' => 86400, // 1 Day,

View file

@ -86,5 +86,8 @@ return [
'unexpected-error' => 'An unexpected error has occurred',
'login-to-get-bundles' => 'to get your bundles',
'you-are-logged-in' => 'You are logged in as ":username"',
'logout' => 'Logout'
'logout' => 'Logout',
'forever' => 'Forever',
'yes' => 'Yes',
'no' => 'No',
];

View file

@ -86,5 +86,8 @@ return [
'unexpected-error' => 'Une erreur inattendue est survenue',
'to-get-bundles' => 'pour accéder à vos archives',
'you-are-logged-in' => 'Vous êtes connecté(e) en tant que ":username"',
'logout' => 'Déconnexion'
'logout' => 'Déconnexion',
'forever' => 'Infinie',
'yes' => 'Oui',
'no' => 'Non',
];

View file

@ -14,20 +14,24 @@
created_at: null,
expires_at: null,
expired: null,
interval: null,
init: function() {
this.updateTimes()
window.setInterval( () => {
this.interval = window.setInterval( () => {
this.updateTimes()
}, 5000)
},
updateTimes: function() {
this.created_at = moment(this.metadata.created_at).fromNow()
if (! this.isExpired()) {
this.expires_at =moment(this.metadata.expires_at).fromNow()
if (this.metadata.expiry) {
if (! this.isExpired()) {
this.expires_at = moment(this.metadata.expires_at).fromNow()
}
}
},
@ -91,7 +95,18 @@
<span class="font-title text-xs text-primary uppercase mr-1">
@lang('app.upload-expiry')
</span>
<span x-text="expires_at"></span>
<template x-if="expires_at">
<span x-text="expires_at"></span>
</template>
<template x-if="! expires_at">
<span>@lang('app.forever')</span>
</template>
</p>
<p class="w-1/2 px-1 mt-1">
<span class="font-title text-xs text-primary uppercase mr-1">
@lang('app.files')
</span>
<span x-text="Object.keys(metadata.files).length"></span>
</p>
<p class="w-1/2 px-1 mt-1">
<span class="font-title text-xs text-primary uppercase mr-1">
@ -99,12 +114,6 @@
</span>
<span x-text="humanSize(metadata.fullsize)"></span>
</p>
<p class="w-1/2 px-1 mt-1">
<span class="font-title text-xs text-primary uppercase mr-1">
@lang('app.max-downloads')
</span>
<span x-text="metadata.max_downloads > 0 ? metadata.max_download : '∞'"></span>
</p>
<p class="w-1/2 px-1 mt-1">
<span class="font-title text-xs text-primary uppercase mr-1">
@lang('app.current-downloads')
@ -113,9 +122,9 @@
</p>
<p class="w-1/2 px-1 mt-1">
<span class="font-title text-xs text-primary uppercase mr-1">
@lang('app.password')
@lang('app.max-downloads')
</span>
<span x-text="metadata.password ? 'yes': 'no'"></span>
<span x-text="metadata.max_downloads > 0 ? metadata.max_downloads : '∞'"></span>
</p>
<p class="w-full px-1 mt-1" x-show="metadata.description">
<span class="font-title text-xs text-primary uppercase mr-1">

View file

@ -259,7 +259,8 @@
}
})
.then( (response) => {
this.syncData(response.data)
//this.syncData(response.data)
window.location.href = '/'
})
.catch( (error) => {
@ -457,9 +458,9 @@
name="expiry"
id="upload-expiry"
>
<option value="0"></option>
<option value="forever">@lang('app.forever')</option>
@foreach (config('sharing.expiry_values') as $k => $e)
<option value="{{ Upload::getExpirySeconds($k) }}" {{ $e == config('sharing.default_expiry') ? 'selected' : '' }}>@lang('app.'.$e)</option>
<option value="{{ Upload::getExpirySeconds($k) }}">@lang('app.'.$e)</option>
@endforeach
</select>
</div>