Skip to content

Commit

Permalink
Adding infinite expiration time
Browse files Browse the repository at this point in the history
  • Loading branch information
axeloz committed Jul 7, 2023
1 parent 3504b0a commit 5d617d6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 29 deletions.
16 changes: 14 additions & 2 deletions app/Http/Controllers/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,14 @@ public function completeBundle(Request $request, Bundle $bundle) {
// 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]);
Expand Down Expand Up @@ -171,7 +178,12 @@ public function deleteBundle(Request $request, Bundle $bundle) {
$f->forceDelete();
}

return response()->json(new BundleResource($bundle));
// Finally deleting bundle
$bundle->forceDelete();

return response()->json([
'success' => true
]);
}
catch (Exception $e) {
return response()->json([
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Middleware/GuestAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function handle(Request $request, Closure $next): Response
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);
Expand Down
22 changes: 11 additions & 11 deletions config/sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
'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,

Expand Down
5 changes: 4 additions & 1 deletion lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@
'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',
];
5 changes: 4 additions & 1 deletion lang/fr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@
'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',
];
29 changes: 19 additions & 10 deletions resources/views/download.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
},
Expand Down Expand Up @@ -91,19 +95,24 @@
<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.fullsize')
@lang('app.files')
</span>
<span x-text="humanSize(metadata.fullsize)"></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">
@lang('app.max-downloads')
@lang('app.fullsize')
</span>
<span x-text="metadata.max_downloads > 0 ? metadata.max_download : '∞'"></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">
Expand All @@ -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">
Expand Down
7 changes: 4 additions & 3 deletions resources/views/upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
}
})
.then( (response) => {
this.syncData(response.data)
//this.syncData(response.data)
window.location.href = '/'
})
.catch( (error) => {
Expand Down Expand Up @@ -457,9 +458,9 @@ class="w-full text-slate-700 bg-transparent h-8 p-0 py-1 border-b border-primary
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>
Expand Down

0 comments on commit 5d617d6

Please sign in to comment.