From 5d617d649c7a9cd4701bcd3388536d02e8e3e486 Mon Sep 17 00:00:00 2001
From: Axel
Date: Fri, 7 Jul 2023 10:42:03 +0200
Subject: [PATCH] Adding infinite expiration time
---
app/Http/Controllers/UploadController.php | 16 +++++++++++--
app/Http/Middleware/GuestAccess.php | 4 +++-
config/sharing.php | 22 ++++++++---------
lang/en/app.php | 5 +++-
lang/fr/app.php | 5 +++-
resources/views/download.blade.php | 29 +++++++++++++++--------
resources/views/upload.blade.php | 7 +++---
7 files changed, 59 insertions(+), 29 deletions(-)
diff --git a/app/Http/Controllers/UploadController.php b/app/Http/Controllers/UploadController.php
index 543b833..d8b229c 100644
--- a/app/Http/Controllers/UploadController.php
+++ b/app/Http/Controllers/UploadController.php
@@ -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]);
@@ -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([
diff --git a/app/Http/Middleware/GuestAccess.php b/app/Http/Middleware/GuestAccess.php
index 557f0aa..51a3802 100644
--- a/app/Http/Middleware/GuestAccess.php
+++ b/app/Http/Middleware/GuestAccess.php
@@ -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);
diff --git a/config/sharing.php b/config/sharing.php
index a5a2c25..c6f691f 100644
--- a/config/sharing.php
+++ b/config/sharing.php
@@ -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,
diff --git a/lang/en/app.php b/lang/en/app.php
index 06885c1..b92e362 100644
--- a/lang/en/app.php
+++ b/lang/en/app.php
@@ -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',
];
diff --git a/lang/fr/app.php b/lang/fr/app.php
index a0d3019..91d2bf1 100644
--- a/lang/fr/app.php
+++ b/lang/fr/app.php
@@ -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',
];
diff --git a/resources/views/download.blade.php b/resources/views/download.blade.php
index 4e09ada..95e8f5e 100644
--- a/resources/views/download.blade.php
+++ b/resources/views/download.blade.php
@@ -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,19 +95,24 @@
@lang('app.upload-expiry')
-
+
+
+
+
+ @lang('app.forever')
+
- @lang('app.fullsize')
+ @lang('app.files')
-
+
- @lang('app.max-downloads')
+ @lang('app.fullsize')
-
+
@@ -113,9 +122,9 @@
- @lang('app.password')
+ @lang('app.max-downloads')
-
+
diff --git a/resources/views/upload.blade.php b/resources/views/upload.blade.php
index e97184e..d45589f 100644
--- a/resources/views/upload.blade.php
+++ b/resources/views/upload.blade.php
@@ -259,7 +259,8 @@
}
})
.then( (response) => {
- this.syncData(response.data)
+ //this.syncData(response.data)
+ window.location.href = '/'
})
.catch( (error) => {
@@ -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"
>
-
+
@foreach (config('sharing.expiry_values') as $k => $e)
-
+
@endforeach