diff --git a/config/language-translations.php b/config/language-translations.php
index 4ed44014..e9b693a7 100644
--- a/config/language-translations.php
+++ b/config/language-translations.php
@@ -338,7 +338,6 @@ return [
'context_menu.share_cancel' => 'Cancel Sharing',
'context_menu.share_edit' => 'Edit Sharing',
'context_menu.upload' => 'Upload',
- 'context_menu.zip_folder' => 'Zip and Download',
'cookie_disclaimer.button' => 'cookies policy',
'cookie_disclaimer.description' => 'By browsing this website you are agreeing to our {0}.',
'datatable.paginate_info' => 'Showing 1 - {visible} from {total} records',
diff --git a/public/mix-manifest.json b/public/mix-manifest.json
index 07a42a5a..4b7c5fd0 100644
--- a/public/mix-manifest.json
+++ b/public/mix-manifest.json
@@ -40,7 +40,7 @@
"/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.js": "/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser.js?id=8a06b7d864acff647f8c",
"/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser~chunks/shared/single-file.js": "/chunks/files~chunks/platform~chunks/shared~chunks/shared/file-browser~chunks/shared/single-file.js?id=0de0b81edf0bb5d4617d",
"/chunks/files~chunks/settings-subscription~chunks/shared/file-browser~chunks/user-subscription.js": "/chunks/files~chunks/settings-subscription~chunks/shared/file-browser~chunks/user-subscription.js?id=c5ec9502bcfad35c502e",
- "/chunks/files~chunks/shared/file-browser.js": "/chunks/files~chunks/shared/file-browser.js?id=5c31a056cb557ade51c2",
+ "/chunks/files~chunks/shared/file-browser.js": "/chunks/files~chunks/shared/file-browser.js?id=1b19035df0776555ab90",
"/chunks/files~chunks/shared/file-browser~chunks/shared/single-file.js": "/chunks/files~chunks/shared/file-browser~chunks/shared/single-file.js?id=ad09e3f973e4db0411f1",
"/chunks/forgotten-password.js": "/chunks/forgotten-password.js?id=8871529af0da8193d3a3",
"/chunks/homepage.js": "/chunks/homepage.js?id=d29b9f09d08d673dff75",
@@ -56,7 +56,7 @@
"/chunks/plan-subscribers.js": "/chunks/plan-subscribers.js?id=320263fdc9aef3a3be60",
"/chunks/plans.js": "/chunks/plans.js?id=0533e61243eeb87b3e8e",
"/chunks/platform.js": "/chunks/platform.js?id=721cb528aaff1d69d58f",
- "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=e5dcf772403613fce36c",
+ "/chunks/platform~chunks/shared.js": "/chunks/platform~chunks/shared.js?id=f7ea7a882f169ecc2c31",
"/chunks/profile.js": "/chunks/profile.js?id=7186e04a6f0f5b6bf470",
"/chunks/profile~chunks/settings-password.js": "/chunks/profile~chunks/settings-password.js?id=ddb7be518c092ed392ca",
"/chunks/purchase-code.js": "/chunks/purchase-code.js?id=85217c42d79948008ed1",
@@ -107,5 +107,24 @@
"/js/main.8b39d84cfbd9e8d53355.hot-update.js": "/js/main.8b39d84cfbd9e8d53355.hot-update.js",
"/js/main.571d6eb6e4cdc38cf4e7.hot-update.js": "/js/main.571d6eb6e4cdc38cf4e7.hot-update.js",
"/js/main.0a092bdc430e651e46a6.hot-update.js": "/js/main.0a092bdc430e651e46a6.hot-update.js",
- "/js/main.a2e4ef0944dba57924a8.hot-update.js": "/js/main.a2e4ef0944dba57924a8.hot-update.js"
+ "/js/main.a2e4ef0944dba57924a8.hot-update.js": "/js/main.a2e4ef0944dba57924a8.hot-update.js",
+ "/js/main.d52a3d051ffb259f0e6f.hot-update.js": "/js/main.d52a3d051ffb259f0e6f.hot-update.js",
+ "/js/main.f694b1fcdad52320eae0.hot-update.js": "/js/main.f694b1fcdad52320eae0.hot-update.js",
+ "/chunks/files~chunks/shared/file-browser.24beea145b487fbe999e.hot-update.js": "/chunks/files~chunks/shared/file-browser.24beea145b487fbe999e.hot-update.js",
+ "/js/main.68f8c97da59bcec0f39e.hot-update.js": "/js/main.68f8c97da59bcec0f39e.hot-update.js",
+ "/js/main.1b0b847042e83c0b0d7b.hot-update.js": "/js/main.1b0b847042e83c0b0d7b.hot-update.js",
+ "/js/main.2354a675171466740151.hot-update.js": "/js/main.2354a675171466740151.hot-update.js",
+ "/js/main.65431fc372485102df15.hot-update.js": "/js/main.65431fc372485102df15.hot-update.js",
+ "/js/main.626dfb15dee5524edb97.hot-update.js": "/js/main.626dfb15dee5524edb97.hot-update.js",
+ "/chunks/files~chunks/shared/file-browser.5047a001f7fdd11a038b.hot-update.js": "/chunks/files~chunks/shared/file-browser.5047a001f7fdd11a038b.hot-update.js",
+ "/chunks/files~chunks/shared/file-browser.611a7944a1e9286325bc.hot-update.js": "/chunks/files~chunks/shared/file-browser.611a7944a1e9286325bc.hot-update.js",
+ "/chunks/files~chunks/shared/file-browser.b343377ecc34e61e966d.hot-update.js": "/chunks/files~chunks/shared/file-browser.b343377ecc34e61e966d.hot-update.js",
+ "/js/main.ba42843c1c7ac82ccafd.hot-update.js": "/js/main.ba42843c1c7ac82ccafd.hot-update.js",
+ "/chunks/files~chunks/shared/file-browser.ba42843c1c7ac82ccafd.hot-update.js": "/chunks/files~chunks/shared/file-browser.ba42843c1c7ac82ccafd.hot-update.js",
+ "/chunks/platform~chunks/shared.ba42843c1c7ac82ccafd.hot-update.js": "/chunks/platform~chunks/shared.ba42843c1c7ac82ccafd.hot-update.js",
+ "/chunks/platform~chunks/shared.5afa70053cbd4fe99bef.hot-update.js": "/chunks/platform~chunks/shared.5afa70053cbd4fe99bef.hot-update.js",
+ "/chunks/platform~chunks/shared.c0f59c4d5f95687a84ad.hot-update.js": "/chunks/platform~chunks/shared.c0f59c4d5f95687a84ad.hot-update.js",
+ "/chunks/platform~chunks/shared.6db75d5fc148ae19b0b8.hot-update.js": "/chunks/platform~chunks/shared.6db75d5fc148ae19b0b8.hot-update.js",
+ "/chunks/platform~chunks/shared.a9aa2769c5345e07f90c.hot-update.js": "/chunks/platform~chunks/shared.a9aa2769c5345e07f90c.hot-update.js",
+ "/chunks/platform~chunks/shared.8a25cb105761d2e120e8.hot-update.js": "/chunks/platform~chunks/shared.8a25cb105761d2e120e8.hot-update.js"
}
diff --git a/resources/js/components/FilesView/ContextMenu.vue b/resources/js/components/FilesView/ContextMenu.vue
index e42ed475..4a795f59 100644
--- a/resources/js/components/FilesView/ContextMenu.vue
+++ b/resources/js/components/FilesView/ContextMenu.vue
@@ -46,8 +46,7 @@
-
-
+
@@ -89,8 +88,7 @@
-
-
+
@@ -103,7 +101,7 @@
-
+
@@ -125,8 +123,7 @@
-
-
+
@@ -146,8 +143,7 @@
-
-
+
@@ -220,9 +216,6 @@ export default {
}
},
methods: {
- downloadFolder() {
- this.$store.dispatch('downloadFolder', this.item)
- },
emptyTrash() {
this.$store.dispatch('emptyTrash')
},
@@ -249,8 +242,8 @@ export default {
}
},
downloadItem() {
- if (this.clipboard.length > 1)
- this.$store.dispatch('downloadFiles')
+ if (this.clipboard.length > 1 || (this.clipboard.length === 1 && this.clipboard[0].type === 'folder'))
+ this.$store.dispatch('downloadZip')
else {
this.$downloadFile(this.item.file_url, this.item.name + '.' + this.item.mimetype)
}
diff --git a/resources/js/components/FilesView/FileMenuMobile.vue b/resources/js/components/FilesView/FileMenuMobile.vue
index 142f9c9f..fbb7d003 100644
--- a/resources/js/components/FilesView/FileMenuMobile.vue
+++ b/resources/js/components/FilesView/FileMenuMobile.vue
@@ -10,8 +10,7 @@
-
-
+
@@ -28,8 +27,7 @@
-
-
+
@@ -47,8 +45,7 @@
-
-
+
@@ -61,16 +58,14 @@
-
-
+
-
-
+
@@ -126,9 +121,6 @@ export default {
}
},
methods: {
- downloadFolder() {
- this.$store.dispatch('downloadFolder', this.clipboard[0])
- },
addToFavourites() {
if (this.favourites && !this.favourites.find(el => el.id === this.clipboard[0].id)) {
this.$store.dispatch('addToFavourites', this.clipboard[0])
@@ -136,12 +128,13 @@ export default {
this.$store.dispatch('removeFromFavourites', this.clipboard[0])
}
},
- downloadItem() {
- this.$downloadFile(
- this.clipboard[0].file_url,
- this.clipboard[0].name + '.' + this.clipboard[0].mimetype
- )
- }
+ downloadItem() {
+ if (this.clipboard.length > 1 || (this.clipboard.length === 1 && this.clipboard[0].type === 'folder'))
+ this.$store.dispatch('downloadZip')
+ else {
+ this.$downloadFile(this.clipboard[0].file_url, this.clipboard[0].name + '.' + this.clipboard[0].mimetype)
+ }
+ },
}
}
diff --git a/resources/js/components/FilesView/MultiSelectToolbarMobile.vue b/resources/js/components/FilesView/MultiSelectToolbarMobile.vue
index e331a4d0..395490b9 100644
--- a/resources/js/components/FilesView/MultiSelectToolbarMobile.vue
+++ b/resources/js/components/FilesView/MultiSelectToolbarMobile.vue
@@ -5,7 +5,7 @@
-
+
@@ -16,17 +16,18 @@
diff --git a/resources/js/store/modules/fileFunctions.js b/resources/js/store/modules/fileFunctions.js
index 2ea7a6d2..47c0a17d 100644
--- a/resources/js/store/modules/fileFunctions.js
+++ b/resources/js/store/modules/fileFunctions.js
@@ -15,26 +15,24 @@ const defaultState = {
}
const actions = {
- downloadFolder: ({getters}, folder) => {
-
- let route = getters.sharedDetail
- ? `/api/zip/folder/${folder.id}/${router.currentRoute.params.token}`
- : `/api/zip/folder/${folder.id}`
-
- Vue.prototype.$downloadFile(route, 'files.zip')
- },
- downloadFiles: ({getters}) => {
+ downloadZip: ({getters}) => {
let files = []
// get ids of selected files
- getters.clipboard.forEach(file => files.push(file.id))
+ getters.clipboard.forEach(file => {
+ let type = file.type === 'folder'
+ ? 'folder'
+ : 'file'
- let ids = files.join(',')
+ files.push(file.id + '|' + type)
+ })
+
+ let items = files.join(',')
// Get route
let route = getters.sharedDetail
- ? `/api/zip/files/${router.currentRoute.params.token}/?ids=${ids}`
- : `/api/zip/files?ids=${ids}`
+ ? `/api/zip/${router.currentRoute.params.token}?items=${items}`
+ : `/api/zip?items=${items}`
Vue.prototype.$downloadFile(route, 'files.zip')
},
diff --git a/routes/api.php b/routes/api.php
index c36b702a..5e6f1c0d 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -2,9 +2,8 @@
use App\Users\Actions\CreateNewUserAction;
use Domain\Pages\Controllers\PagesController;
-use Domain\Zip\Controllers\ZipFilesController;
+use Domain\Zip\Controllers\ZipController;
use Domain\Sharing\Controllers\ShareController;
-use Domain\Zip\Controllers\ZipFolderController;
use Domain\Trash\Controllers\DumpTrashController;
use App\Users\Controllers\ResetPasswordController;
use Domain\Files\Controllers\UploadFileController;
@@ -80,6 +79,5 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
Route::post('/remove', DeleteFileOrFolderController::class);
Route::post('/move', MoveFileOrFolderController::class);
- Route::get('/zip/folder/{id}', ZipFolderController::class);
- Route::get('/zip/files', ZipFilesController::class);
+ Route::get('/zip', ZipController::class);
});
diff --git a/src/Domain/Zip/Actions/ZipAction.php b/src/Domain/Zip/Actions/ZipAction.php
new file mode 100644
index 00000000..d0b24e72
--- /dev/null
+++ b/src/Domain/Zip/Actions/ZipAction.php
@@ -0,0 +1,86 @@
+user_id;
+
+ // Create zip
+ $zip = Zip::create('files.zip');
+
+ // Zip Files
+ $files->map(function ($file) use ($zip) {
+ // get file path
+ $filePath = "files/$file->user_id/$file->basename";
+
+ // Add file into zip
+ if (Storage::exists($filePath)) {
+ // local disk
+ if (is_storage_driver('local')) {
+ $zip->add(Storage::path($filePath), $file->name);
+ }
+
+ // s3 client
+ if (is_storage_driver('s3')) {
+ $bucketName = config('filesystems.disks.s3.bucket');
+
+ $zip->add("s3://$bucketName/$filePath", $file->name);
+ }
+ }
+ });
+
+ // Zip Folders
+ $folders->map(function ($folder) use ($zip, $user_id) {
+ // Get folder
+ $requested_folder = Folder::with(['folders.files', 'files'])
+ ->where('id', $folder->id)
+ ->where('user_id', $user_id)
+ ->with('folders')
+ ->first();
+
+ $folderFiles = get_files_for_zip($requested_folder, collect([]));
+
+ foreach ($folderFiles as $file) {
+ // get file path
+ $filePath = "files/$user_id/{$file['basename']}";
+
+ // Add file into zip
+ if (Storage::exists($filePath)) {
+ $zipDestination = "{$file['folder_path']}/{$file['name']}";
+
+ // local disk
+ if (is_storage_driver('local')) {
+ $zip->add(Storage::path($filePath), $zipDestination);
+ }
+
+ // s3 client
+ if (is_storage_driver('s3')) {
+ $bucketName = config('filesystems.disks.s3.bucket');
+
+ $zip->add("s3://$bucketName/$filePath", $zipDestination);
+ }
+ }
+ }
+ });
+
+ return $zip;
+ }
+}
\ No newline at end of file
diff --git a/src/Domain/Zip/Actions/ZipFilesAction.php b/src/Domain/Zip/Actions/ZipFilesAction.php
deleted file mode 100644
index 4d2bb7aa..00000000
--- a/src/Domain/Zip/Actions/ZipFilesAction.php
+++ /dev/null
@@ -1,45 +0,0 @@
-map(function ($file) use ($zip) {
- // get file path
- $filePath = "files/$file->user_id/$file->basename";
-
- // Add file into zip
- if (Storage::exists($filePath)) {
- // local disk
- if (is_storage_driver('local')) {
- $zip->add(Storage::path($filePath), $file->name);
- }
-
- // s3 client
- if (is_storage_driver('s3')) {
- $bucketName = config('filesystems.disks.s3.bucket');
-
- $zip->add("s3://$bucketName/$filePath", $file->name);
- }
- }
- });
-
- return $zip;
- }
-}
diff --git a/src/Domain/Zip/Actions/ZipFolderAction.php b/src/Domain/Zip/Actions/ZipFolderAction.php
deleted file mode 100644
index 9bd15166..00000000
--- a/src/Domain/Zip/Actions/ZipFolderAction.php
+++ /dev/null
@@ -1,58 +0,0 @@
-user_id;
-
- // Get folder
- $requested_folder = Folder::with(['folders.files', 'files'])
- ->where('id', $id)
- ->where('user_id', $user_id)
- ->with('folders')
- ->first();
-
- $files = get_files_for_zip($requested_folder, collect([]));
-
- // Create zip
- $zip = Zip::create('files.zip');
-
- foreach ($files as $file) {
- // get file path
- $filePath = "files/$user_id/{$file['basename']}";
-
- // Add file into zip
- if (Storage::exists($filePath)) {
- $zipDestination = "{$file['folder_path']}/{$file['name']}";
-
- // local disk
- if (is_storage_driver('local')) {
- $zip->add(Storage::path($filePath), $zipDestination);
- }
-
- // s3 client
- if (is_storage_driver('s3')) {
- $bucketName = config('filesystems.disks.s3.bucket');
-
- $zip->add("s3://$bucketName/$filePath", $zipDestination);
- }
- }
- }
-
- return $zip;
- }
-}
diff --git a/src/Domain/Zip/Controllers/ZipController.php b/src/Domain/Zip/Controllers/ZipController.php
new file mode 100644
index 00000000..0a83818d
--- /dev/null
+++ b/src/Domain/Zip/Controllers/ZipController.php
@@ -0,0 +1,65 @@
+get('items'));
+
+ $itemList = collect($items)
+ ->map(function ($chunk) {
+ $items = explode('|', $chunk);
+
+ return [
+ 'id' => $items[0],
+ 'type' => $items[1],
+ ];
+ });
+
+ $folderIds = $itemList
+ ->where('type', 'folder')
+ ->pluck('id');
+
+ $fileIds = $itemList
+ ->where('type', 'file')
+ ->pluck('id');
+
+ $folders = Folder::whereUserId($user_id)
+ ->whereIn('id', $folderIds)
+ ->get();
+
+ $files = File::whereUserId($user_id)
+ ->whereIn('id', $fileIds)
+ ->get();
+
+ $zip = ($this->zip)($folders, $files);
+
+ ($this->recordDownload)(
+ file_size: $zip->predictZipSize(),
+ user_id: $user_id,
+ );
+
+ return $zip;
+ }
+}
\ No newline at end of file
diff --git a/src/Domain/Zip/Controllers/ZipFilesController.php b/src/Domain/Zip/Controllers/ZipFilesController.php
deleted file mode 100644
index 82addecd..00000000
--- a/src/Domain/Zip/Controllers/ZipFilesController.php
+++ /dev/null
@@ -1,36 +0,0 @@
-whereIn('id', explode(',', $request->get('ids')))
- ->get();
-
- $zip = ($this->zipFiles)($files);
-
- ($this->recordDownload)(
- file_size: $zip->predictZipSize(),
- user_id: Auth::id(),
- );
-
- return $zip;
- }
-}
diff --git a/src/Domain/Zip/Controllers/ZipFolderController.php b/src/Domain/Zip/Controllers/ZipFolderController.php
deleted file mode 100644
index f131ad74..00000000
--- a/src/Domain/Zip/Controllers/ZipFolderController.php
+++ /dev/null
@@ -1,38 +0,0 @@
-where('id', $id);
-
- if (! $folder->exists()) {
- response("Requested folder doesn't exists.", 404);
- }
-
- $zip = ($this->zipFolder)($id);
-
- ($this->recordDownload)(
- file_size: $zip->predictZipSize(),
- user_id: Auth::id(),
- );
-
- return $zip;
- }
-}
diff --git a/tests/Domain/Zip/UserZippingTest.php b/tests/Domain/Zip/UserZippingTest.php
index 98778953..b0ab883c 100644
--- a/tests/Domain/Zip/UserZippingTest.php
+++ b/tests/Domain/Zip/UserZippingTest.php
@@ -1,4 +1,5 @@
create([
+ 'user_id' => $user->id,
+ ]);
+
+ collect([0, 1])
+ ->each(function ($index) use ($folder) {
+ $file = UploadedFile::fake()
+ ->create("fake-inner-file-$index.pdf", 1200, 'application/pdf');
+
+ $this->postJson('/api/upload', [
+ 'filename' => $file->name,
+ 'file' => $file,
+ 'folder_id' => $folder->id,
+ 'is_last' => 'true',
+ ])->assertStatus(201);
+ });
+
collect([0, 1])
->each(function ($index) {
$file = UploadedFile::fake()
@@ -34,12 +53,13 @@ class UserZippingTest extends TestCase
])->assertStatus(201);
});
- $file_ids = File::all()->pluck('id')->toArray();
-
- $ids = implode(',', $file_ids);
+ $files = File::all()
+ ->where('folder_id', null)
+ ->pluck('id')
+ ->toArray();
$this
- ->getJson("/api/zip/files?ids=$ids")
+ ->getJson("/api/zip?items=$files[0]|file,$files[1]|file,$folder->id|folder")
->assertStatus(200)
->assertHeader('content-type', 'application/x-zip');
}
@@ -72,7 +92,7 @@ class UserZippingTest extends TestCase
])->assertStatus(201);
});
- $this->getJson("/api/zip/folder/$folder->id")
+ $this->getJson("/api/zip?items=$folder->id|folder")
->assertStatus(200)
->assertHeader('content-type', 'application/x-zip');
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 46d045c8..c1648da8 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -25,6 +25,6 @@ abstract class TestCase extends BaseTestCase
resolve(CreateDiskDirectoriesAction::class)();
- $this->withoutExceptionHandling();
+ //$this->withoutExceptionHandling();
}
}