diff --git a/app/Http/Controllers/UploadController.php b/app/Http/Controllers/UploadController.php
index 3e6595a..ae39986 100644
--- a/app/Http/Controllers/UploadController.php
+++ b/app/Http/Controllers/UploadController.php
@@ -166,7 +166,7 @@ class UploadController extends Controller
$metadata = Upload::getMetadata($bundleId);
// Forcing file to expire
- $metadata['expires_at'] = time() - 1000;
+ $metadata['expires_at'] = time() - (3600 * 24 * 30);
// Rewriting the metadata file
try {
diff --git a/lang/en/app.php b/lang/en/app.php
index d31ae74..c100434 100644
--- a/lang/en/app.php
+++ b/lang/en/app.php
@@ -8,7 +8,7 @@ return [
'warning-bundle-expired' => 'Bundle has expired',
'download-all' => 'Download all',
'for' => 'for',
- 'files' => 'file|files',
+ 'files' => 'file(s)',
'no-file-in-this-bundle' => 'No file into this bundle',
'maximum-filesize' => 'Max filesize :',
'preview-link' => 'Preview link',
@@ -70,6 +70,12 @@ return [
'files-remaining-files' => 'Number of remaining files allowed',
'delete-bundle' => 'Delete bundle',
'confirm-delete-bundle' => 'Do you really want to delete this bundle?',
- 'bundle-expired' => 'This bundle has expired'
+ 'bundle-expired' => 'This bundle has expired',
+ 'active' => 'Active',
+ 'expired' => 'Expired',
+ 'existing-bundles' => 'Your existing bundles',
+ 'or-create' => 'New bundle',
+ 'no-existing-bundle' => 'No existing bundle'
+
];
diff --git a/lang/fr/app.php b/lang/fr/app.php
index 9ecfda9..e594171 100644
--- a/lang/fr/app.php
+++ b/lang/fr/app.php
@@ -8,7 +8,7 @@ return [
'warning-bundle-expired' => 'L\'archive a expiré',
'download-all' => 'Tout télécharger',
'for' => 'pour',
- 'files' => 'fichier|fichiers',
+ 'files' => 'fichier(s)',
'no-file-in-this-bundle' => 'Aucun fichier dans cette archive',
'maximum-filesize' => 'Taille maximum :',
'preview-link' => 'Lien de visualisation',
@@ -70,6 +70,12 @@ return [
'files-remaining-files' => 'Nombre de fichiers restants autorisés',
'delete-bundle' => 'Supprimer l\'archive',
'confirm-delete-bundle' => 'Voulez-vous supprimer cette archive ?',
- 'bundle-expired' => 'Cette archive a expiré'
+ 'bundle-expired' => 'Cette archive a expiré',
+ 'active' => 'Actifs',
+ 'expired' => 'Expirés',
+ 'existing-bundles' => 'Vos archives existantes',
+ 'or-create' => 'Nouvelle archive',
+ 'no-existing-bundle' => 'Aucune archive existante'
+
];
diff --git a/resources/views/homepage.blade.php b/resources/views/homepage.blade.php
index 7a403cd..6eba97c 100644
--- a/resources/views/homepage.blade.php
+++ b/resources/views/homepage.blade.php
@@ -6,16 +6,39 @@
document.addEventListener('alpine:init', () => {
Alpine.data('bundle', () => ({
bundles: null,
+ currentBundle: null,
init: function() {
+ // Getting bundles stored locally
bundles = localStorage.getItem('bundles');
+ // And JSON decoding it
+ this.bundles = JSON.parse(bundles)
- if (bundles == null || bundles == '') {
- console.log('creating bundles')
- this.bundles = []
+ if (this.bundles != null && Object.keys(this.bundles).length > 0) {
+ this.bundles.active = []
+ this.bundles.expired = []
+
+ this.bundles.forEach( (bundle) => {
+ if (bundle.title == null || bundle.title == '') {
+ bundle.title = 'untitled'
+ }
+
+ bundle.title += ' - '+Object.keys(bundle.files).length+' {{ __('app.files') }} - {{ __('app.created-at') }} '+moment.unix(bundle.created_at).fromNow()
+
+ if (bundle.expires_at != null && moment.unix(bundle.expires_at).isBefore(moment())) {
+ this.bundles.expired.push(bundle)
+ }
+ else {
+ this.bundles.active.push(bundle)
+ }
+ })
+
+ console.log(this.bundles)
}
- else {
- this.bundles = JSON.parse(bundles)
+
+ // If bundle is empty, initializing it
+ if (this.bundles == null || this.bundles == '') {
+ this.bundles = []
}
},
@@ -23,9 +46,10 @@
// Generating a new bundle key pair
const pair = {
bundle_id: this.generateStr(30),
- owner_token: this.generateStr(15)
+ owner_token: this.generateStr(15),
+ created_at: moment().unix()
}
- this.bundles.push(pair)
+ this.bundles.unshift(pair)
// Storing them locally
localStorage.setItem('bundles', JSON.stringify(this.bundles))
@@ -56,7 +80,21 @@
}
return result;
- }
+ },
+
+ redirectToBundle: function() {
+ if (this.currentBundle != null) {
+ window.location.href = '/upload/'+this.currentBundle
+ }
+ },
+
+ isBundleExpired: function() {
+ if (this.metadata.expires_at == null || this.metadata.expires_at == '') {
+ return false;
+ }
+
+ return moment.unix(this.metadata.expires_at).isBefore(moment())
+ },
}))
})
@@ -67,15 +105,48 @@
-
{{ config('app.name') }}
-
-
- @lang('app.create-new-upload')
-
+
+
@lang('app.existing-bundles')
+
+
@lang('app.no-existing-bundle')
+
+
+
@lang('app.or-create')
+
+
diff --git a/resources/views/upload.blade.php b/resources/views/upload.blade.php
index 5cb8bf5..97b5215 100644
--- a/resources/views/upload.blade.php
+++ b/resources/views/upload.blade.php
@@ -10,12 +10,14 @@
document.addEventListener('alpine:init', () => {
Alpine.data('upload', () => ({
bundle: null,
+ bundleIndex: null,
bundles: null,
dropzone: null,
uploadedFiles: [],
metadata: [],
completed: false,
step: 0,
+ maxFiles: maxFiles,
modal: {
show: false,
text: 'test'
@@ -54,33 +56,38 @@
this.step = 1
}
}
-
},
getBundle: function() {
// Getting all bundles store in local storage
bundles = localStorage.getItem('bundles')
+
// If not bundle found, back to homepage
if (bundles == null || bundles == '') {
window.location.href = '/'
return false
}
+
this.bundles = JSON.parse(bundles)
// Looking for the current bundle
- this.bundles.forEach(element => {
- if (element.bundle_id == this.metadata.bundle_id) {
- this.bundle = element
- }
- })
+ if (this.bundles != null && Object.keys(this.bundles).length > 0) {
+ this.bundles.forEach( (element, index) => {
+ if (element.bundle_id == this.metadata.bundle_id) {
+ //this.bundle = Object.assign(element)
+ //this.bundleIndex = index
+ this.bundle = index
+ }
+ })
+ }
// If current bundle not found, aborting
- if (this.bundle == null || this.bundle == '') {
+ if (this.bundle == null) {
window.location.href = '/'
return false
}
- if (this.bundle.owner_token != this.metadata.owner_token) {
+ if (this.bundles[this.bundle].owner_token != this.metadata.owner_token) {
window.location.href = '/'
return false
}
@@ -124,11 +131,11 @@
description: this.metadata.description,
max_downloads: this.metadata.max_downloads,
password: this.metadata.password,
- auth: this.bundle.owner_token
+ auth: this.bundles[this.bundle].owner_token
}
})
.then( (response) => {
- this.metadata = response.data
+ this.syncData(response.data)
window.history.pushState(null, null, baseUrl+'/upload/'+this.metadata.bundle_id);
this.step = 2
@@ -149,13 +156,13 @@
url: '/upload/'+this.metadata.bundle_id+'/complete',
method: 'POST',
data: {
- auth: this.bundle.owner_token
+ auth: this.bundles[this.bundle].owner_token
}
})
.then( (response) => {
this.step = 3
- this.metadata = response.data
+ this.syncData(response.data)
})
.catch( (error) => {
// TODO: do something here
@@ -171,13 +178,13 @@
startDropzone: function() {
if (! this.dropzone) {
- maxFiles = maxFiles - this.countFilesOnServer() >= 0 ? maxFiles - this.countFilesOnServer() : 0
+ this.maxFiles = this.maxFiles - this.countFilesOnServer() >= 0 ? this.maxFiles - this.countFilesOnServer() : 0
this.dropzone = new Dropzone('#upload-frm', {
url: '/upload/'+this.metadata.bundle_id+'/file',
method: 'POST',
headers: {
- 'X-Upload-Auth': this.bundle.owner_token
+ 'X-Upload-Auth': this.bundles[this.bundle].owner_token
},
createImageThumbnails: false,
disablePreviews: true,
@@ -190,12 +197,10 @@
dictFileTooBig: '@lang('app.file-too-big')',
dictDefaultMessage: '@lang('app.dropzone-text')',
dictResponseError: '@lang('app.server-answered')',
- // init: function() {
- // this.options.maxFiles = this.options.maxFiles - currentFilesCount
- // }
})
this.dropzone.on("addedfile", (file) => {
+ console.log('added file')
this.metadata.files.push({
uuid: file.upload.uuid,
original: file.name,
@@ -226,6 +231,7 @@
this.metadata.files[fileIndex].progress = 0
if (file.status == 'success') {
+ this.maxFiles--
this.metadata.files[fileIndex].status = true
}
})
@@ -260,11 +266,11 @@
method: 'DELETE',
data: {
file: lfile.uuid,
- auth: this.bundle.owner_token
+ auth: this.bundles[this.bundle].owner_token
}
})
.then( (response) => {
- this.metadata = response.data
+ this.syncData(response.data)
})
.catch( (error) => {
// TODO: do something here
@@ -282,6 +288,14 @@
}
},
+ syncData: function(metadata) {
+ if (Object.keys(metadata).length > 0) {
+ this.metadata = metadata
+ this.bundles[this.bundle] = metadata
+ localStorage.setItem('bundles', JSON.stringify(this.bundles))
+ }
+ },
+
humanSize: function(val) {
if (val >= 100000000) {
return (val / 1000000000).toFixed(1) + ' Go'
@@ -345,12 +359,12 @@
url: '/upload/'+this.metadata.bundle_id+'/delete',
method: 'DELETE',
data: {
- auth: this.bundle.owner_token
+ auth: this.bundles[this.bundle].owner_token
}
})
.then( (response) => {
if (! response.data.success) {
- this.metadata = response.data
+ this.syncData(response.data)
}
})
})