From 0d017dd8da173cadf896c9ae4882343042dc589b Mon Sep 17 00:00:00 2001 From: Stream Date: Wed, 8 Jan 2020 17:44:46 +0800 Subject: [PATCH] remove some configs --- src/Lfm.php | 11 +- src/config/lfm.php | 68 ++---- src/views/resize.blade.php | 4 +- tests/ApiTest.php.bak | 386 -------------------------------- tests/LfmTest.php | 34 +-- tests/TestCase.php.bak | 169 -------------- tests/TestConfigHandler.php.bak | 11 - 7 files changed, 32 insertions(+), 651 deletions(-) delete mode 100644 tests/ApiTest.php.bak delete mode 100644 tests/TestCase.php.bak delete mode 100644 tests/TestConfigHandler.php.bak diff --git a/src/Lfm.php b/src/Lfm.php index c69a95c5..4a3607ea 100644 --- a/src/Lfm.php +++ b/src/Lfm.php @@ -101,7 +101,7 @@ public function getDisplayMode() public function getUserSlug() { - $config = $this->config->get('lfm.user_folder_name'); + $config = $this->config->get('lfm.private_folder_name'); if (is_callable($config)) { return call_user_func($config); @@ -138,11 +138,6 @@ public function getThumbFolderName() return $this->config->get('lfm.thumb_folder_name'); } - public function getFileIcon($ext) - { - return $this->config->get("lfm.file_icon_array.{$ext}", 'fa-file-o'); - } - public function getFileType($ext) { return $this->config->get("lfm.file_type_array.{$ext}", 'File'); @@ -165,7 +160,7 @@ public function maxUploadSize() */ public function allowMultiUser() { - return $this->config->get('lfm.allow_multi_user') === true; + return $this->config->get('lfm.allow_private_folder') === true; } /** @@ -180,7 +175,7 @@ public function allowShareFolder() return true; } - return $this->config->get('lfm.allow_share_folder') === true; + return $this->config->get('lfm.allow_shared_folder') === true; } /** diff --git a/src/config/lfm.php b/src/config/lfm.php index af5a4e43..cb561732 100644 --- a/src/config/lfm.php +++ b/src/config/lfm.php @@ -17,35 +17,33 @@ 'use_package_routes' => true, - // // Use relative paths (without domain) - // 'relative_paths' => false, - /* |-------------------------------------------------------------------------- - | Multi-User Mode + | Shared folder / Private folder |-------------------------------------------------------------------------- + | + | If both options are set to false, then shared folder will be activated. + | */ - 'allow_multi_user' => true, - - 'allow_share_folder' => true, - - /* - |-------------------------------------------------------------------------- - | Folder Names - |-------------------------------------------------------------------------- - */ + 'allow_private_folder' => true, // Flexible way to customize client folders accessibility // If you want to customize client folders, publish tag="lfm_handler" // Then you can rewrite userField function in App\Handler\ConfigHandler class // And set 'user_field' to App\Handler\ConfigHandler::class // Ex: The private folder of user will be named as the user id. - 'user_folder_name' => UniSharp\LaravelFilemanager\Handlers\ConfigHandler::class, + 'private_folder_name' => UniSharp\LaravelFilemanager\Handlers\ConfigHandler::class, + + 'allow_shared_folder' => true, 'shared_folder_name' => 'shares', - 'thumb_folder_name' => 'thumbs', + /* + |-------------------------------------------------------------------------- + | Folder Names + |-------------------------------------------------------------------------- + */ 'folder_categories' => [ 'file' => [ @@ -94,15 +92,6 @@ 'should_validate_mime' => false, - // permissions to be set when create a new folder or when it creates automatically with thumbnails - 'create_folder_mode' => 0755, - - // permissions to be set on file upload. - 'create_file_mode' => 0644, - - // If true, it will attempt to chmod the file after upload - 'should_change_file_mode' => true, - // behavior on files with identical name // setting it to true cause old file replace with new one // setting it to false show `error-file-exist` error and stop upload @@ -117,6 +106,8 @@ // If true, image thumbnails would be created during upload 'should_create_thumbnails' => true, + 'thumb_folder_name' => 'thumbs', + // Create thumbnails automatically only for listed types. 'raster_mimetypes' => [ 'image/jpeg', @@ -124,19 +115,9 @@ 'image/png', ], - 'thumb_img_width' => 200, + 'thumb_img_width' => 200, // px - 'thumb_img_height' => 200, - - /* - |-------------------------------------------------------------------------- - | jQuery UI options - |-------------------------------------------------------------------------- - */ - - 'resize_aspectRatio' => false, - - 'resize_containment' => true, + 'thumb_img_height' => 200, // px /* |-------------------------------------------------------------------------- @@ -159,21 +140,6 @@ 'pptx' => 'Microsoft PowerPoint', ], - 'file_icon_array' => [ - 'pdf' => 'fa-file-pdf-o', - 'doc' => 'fa-file-word-o', - 'docx' => 'fa-file-word-o', - 'xls' => 'fa-file-excel-o', - 'xlsx' => 'fa-file-excel-o', - 'zip' => 'fa-file-archive-o', - 'gif' => 'fa-file-image-o', - 'jpg' => 'fa-file-image-o', - 'jpeg' => 'fa-file-image-o', - 'png' => 'fa-file-image-o', - 'ppt' => 'fa-file-powerpoint-o', - 'pptx' => 'fa-file-powerpoint-o', - ], - /* |-------------------------------------------------------------------------- | php.ini override diff --git a/src/views/resize.blade.php b/src/views/resize.blade.php index 3f783e33..f4134f75 100644 --- a/src/views/resize.blade.php +++ b/src/views/resize.blade.php @@ -78,10 +78,8 @@ renderResizedValues($("#width_display").val(), $("#height_display").val()); $("#resize").resizable({ - aspectRatio: {{ config('lfm.resize_aspectRatio')?'true':'false' }}, - @if(config('lfm.resize_containment')) + aspectRatio: true, containment: "#containment", - @endif handles: "n, e, s, w, se, sw, ne, nw", resize: function (event, ui) { renderResizedValues(ui.size.width, ui.size.height); diff --git a/tests/ApiTest.php.bak b/tests/ApiTest.php.bak deleted file mode 100644 index 3a1e8450..00000000 --- a/tests/ApiTest.php.bak +++ /dev/null @@ -1,386 +0,0 @@ -filename = $uniq . '.jpg'; - $this->filename_s = $uniq . '_S.jpg'; - $this->file = UploadedFile::fake()->image($this->filename); - - $this->dir_name = uniqid(); - } - - public function tearDown() - { - $storage_path = implode(DIRECTORY_SEPARATOR, [ - config('lfm.base_directory'), - config('lfm.files_folder_name'), - (new TestConfigHandler)->userField(), - ]); - Storage::deleteDirectory($storage_path); - parent::tearDown(); - } - - /** - * test directory api. - * - * @group directory - */ - public function testFolder() - { - // auth()->loginUsingId(1); - - $create = $this->getResponseByRouteName('getAddfolder', [ - 'name' => 'testcase', - ]); - - $create_duplicate = $this->getResponseByRouteName('getAddfolder', [ - 'name' => 'testcase', - ]); - - $create_empty = $this->getResponseByRouteName('getAddfolder', [ - 'name' => '', - ]); - - Config::set('lfm.alphanumeric_directory', true); - $create_alphanumeric = $this->getResponseByRouteName('getAddfolder', [ - 'name' => '測試資料夾', - ]); - - $rename = $this->getResponseByRouteName('getRename', [ - 'file' => 'testcase', - 'new_name' => 'testcase2', - ]); - - $delete = $this->getResponseByRouteName('getDelete', [ - 'items' => 'testcase2', - ]); - - $this->assertEquals('OK', $create); - $this->assertEquals(trans('laravel-filemanager::lfm.error-folder-exist'), $create_duplicate); - $this->assertEquals(trans('laravel-filemanager::lfm.error-folder-name'), $create_empty); - $this->assertEquals(trans('laravel-filemanager::lfm.error-folder-alnum'), $create_alphanumeric); - $this->assertEquals('OK', $rename); - $this->assertEquals('OK', $delete); - } - - /** - * upload a file. - * - * @group image - */ - public function testUploadImage() - { - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($this->filename, $this->filename_s, $this->root_dir); - $this->assertFileExists($files_path['file']); - $this->assertFileExists($files_path['file_s']); - } - - /** - * delete a file. - * - * @group image - * @group delete - */ - public function testDeleteImage() - { - $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - $response = $this->json('GET', route('unisharp.lfm.getDelete'), [ - 'items' => $this->filename, - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($this->filename, $this->filename_s, $this->root_dir); - $this->assertFileNotExists($files_path['file']); - $this->assertFileNotExists($files_path['file_s']); - } - - /** - * upload file which exists already. - * - * @group image - * @group doubleUpload - */ - public function testDoubleUpload() - { - $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - $this->assertEquals($response->getContent(), '["A file with this name already exists!"]'); - } - - /** - * change file name. - * - * @group image - * @group rename - */ - public function testRenameImage() - { - $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - $uniq = uniqid(); - $new_name = $uniq . '.jpg'; - $new_name_s = $uniq . '_S.jpg'; - $response = $this->json('GET', route('unisharp.lfm.getRename'), [ - 'file' => $this->filename, - 'new_name' => $new_name, - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($new_name, $new_name_s, $this->root_dir); - $this->assertFileExists($files_path['file']); - $this->assertFileExists($files_path['file_s']); - } - - /** - * add directory. - * - * @group directory - */ - public function testAddDirectory() - { - $response = $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $dir_path = $this->getStoragedFilePath($this->dir_name, $this->root_dir); - $this->assertFileExists($dir_path); - } - - /** - * delete directory. - * - * @group directory - * @group delete - */ - public function testDeleteDirectory() - { - $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - $reponse = $this->json('GET', route('unisharp.lfm.getDelete'), [ - 'items' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - - $reponse->assertStatus(200); - - $dir_path = $this->getStoragedFilePath($this->dir_name, $this->root_dir); - $this->assertFileNotExists($dir_path); - } - - /** - * rename directory. - * - * @group directory - * @group rename - */ - public function testRenameDirectory() - { - $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - $new_dir_name = uniqid(); - $response = $this->json('GET', route('unisharp.lfm.getRename'), [ - 'file' => $this->dir_name, - 'new_name' => $new_dir_name, - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $new_dir_path = $this->getStoragedFilePath($new_dir_name, $this->root_dir); - $this->assertFileExists($new_dir_path); - } - - /** - * upload file in a directory. - * - * @group image - * @group directory - */ - public function testUploadFileInDirectory() - { - $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - $working_dir = $this->root_dir . DIRECTORY_SEPARATOR . $this->dir_name; - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $working_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($this->filename, $this->filename_s, $working_dir); - $this->assertFileExists($files_path['file']); - $this->assertFileExists($files_path['file_s']); - } - - /** - * delete file in a directory. - * - * @group image - * @group directory - */ - public function testDeleteFileInDirectory() - { - $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - - $working_dir = $this->root_dir . DIRECTORY_SEPARATOR . $this->dir_name; - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $working_dir, - ]); - - $reponse = $this->json('GET', route('unisharp.lfm.getDelete'), [ - 'items' => $this->filename, - 'working_dir' => $working_dir, - ]); - - $reponse->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($this->filename, $this->filename_s, $working_dir); - $this->assertFileNotExists($files_path['file']); - $this->assertFileNotExists($files_path['file_s']); - } - - /** - * rename file in directory. - * - * @group image - * @group directory - */ - public function testRenameFileInDirectory() - { - $this->json('GET', route('unisharp.lfm.getAddfolder'), [ - 'name' => $this->dir_name, - 'working_dir' => $this->root_dir, - ]); - - $working_dir = $this->root_dir . DIRECTORY_SEPARATOR . $this->dir_name; - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $working_dir, - ]); - - $uniq = uniqid(); - $new_name = $uniq . '.jpg'; - $new_name_s = $uniq . '_S.jpg'; - $response = $this->json('GET', route('unisharp.lfm.getRename'), [ - 'file' => $this->filename, - 'new_name' => $new_name, - 'working_dir' => $working_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($new_name, $new_name_s, $working_dir); - $this->assertFileExists($files_path['file']); - $this->assertFileExists($files_path['file_s']); - } - - /** - * upload file with lfm.rename_file = true. - * - * @group image - */ - public function testUploadImageWithRename() - { - config(['lfm.rename_file' => true]); - $response = $this->json('GET', route('unisharp.lfm.upload'), [ - 'upload' => [$this->file], - 'working_dir' => $this->root_dir, - ]); - - $response->assertStatus(200); - - $files_path = $this->getStoragedFilePathWithThumb($this->filename, $this->filename_s, $this->root_dir); - $this->assertFileNotExists($files_path['file']); - $this->assertFileNotExists($files_path['file_s']); - } - - /* - * upload file with lfm.alphanumeric_filename = true - * - * @group image - * @group - */ -} diff --git a/tests/LfmTest.php b/tests/LfmTest.php index 32f6b4d2..5e648128 100644 --- a/tests/LfmTest.php +++ b/tests/LfmTest.php @@ -46,10 +46,10 @@ public function testGetNameFromPath() public function testAllowFolderType() { $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(true); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(false); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(true); - $config->shouldReceive('get')->with('lfm.allow_share_folder')->once()->andReturn(false); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true); + $config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false); $lfm = new Lfm($config); @@ -105,7 +105,7 @@ public function testCurrentLfmType() public function testGetUserSlug() { $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.user_folder_name')->once()->andReturn(function () { + $config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () { return 'foo'; }); @@ -117,8 +117,8 @@ public function testGetUserSlug() public function testGetRootFolder() { $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->andReturn(true); - $config->shouldReceive('get')->with('lfm.user_folder_name')->once()->andReturn(function () { + $config->shouldReceive('get')->with('lfm.allow_private_folder')->andReturn(true); + $config->shouldReceive('get')->with('lfm.private_folder_name')->once()->andReturn(function () { return 'foo'; }); $config->shouldReceive('get')->with('lfm.shared_folder_name')->once()->andReturn('bar'); @@ -139,18 +139,6 @@ public function testGetThumbFolderName() $this->assertEquals('foo', $lfm->getThumbFolderName()); } - public function testGetFileIcon() - { - $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.file_icon_array.foo', m::type('string'))->once()->andReturn('fa-foo'); - $config->shouldReceive('get')->with(m::type('string'), m::type('string'))->once()->andReturn('fa-file'); - - $lfm = new Lfm($config); - - $this->assertEquals('fa-foo', $lfm->getFileIcon('foo')); - $this->assertEquals('fa-file', $lfm->getFileIcon('bar')); - } - public function testGetFileType() { $config = m::mock(Config::class); @@ -166,7 +154,7 @@ public function testGetFileType() public function testAllowMultiUser() { $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(true); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true); $lfm = new Lfm($config); @@ -176,9 +164,9 @@ public function testAllowMultiUser() public function testAllowShareFolder() { $config = m::mock(Config::class); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(false); - $config->shouldReceive('get')->with('lfm.allow_multi_user')->once()->andReturn(true); - $config->shouldReceive('get')->with('lfm.allow_share_folder')->once()->andReturn(false); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(false); + $config->shouldReceive('get')->with('lfm.allow_private_folder')->once()->andReturn(true); + $config->shouldReceive('get')->with('lfm.allow_shared_folder')->once()->andReturn(false); $lfm = new Lfm($config); diff --git a/tests/TestCase.php.bak b/tests/TestCase.php.bak deleted file mode 100644 index d77dc2d8..00000000 --- a/tests/TestCase.php.bak +++ /dev/null @@ -1,169 +0,0 @@ -set('lfm.use_package_routes', true); - - $app['config']->set('lfm.middlewares', []); - - $app['config']->set('lfm.prefix', 'laravel-filemanager'); - - $app['config']->set('lfm.urls_prefix', ''); - - $app['config']->set('lfm.allow_multi_user', true); - $app['config']->set('lfm.allow_share_folder', true); - - $app['config']->set('lfm.user_field', TestConfigHandler::class); - - $app['config']->set('lfm.base_directory', 'public'); - - $app['config']->set('lfm.images_folder_name', 'photos'); - $app['config']->set('lfm.files_folder_name', 'files'); - - $app['config']->set('lfm.shared_folder_name', 'shares'); - $app['config']->set('lfm.thumb_folder_name', 'thumbs'); - - $app['config']->set('lfm.images_startup_view', 'grid'); - $app['config']->set('lfm.files_startup_view', 'list'); - - $app['config']->set('lfm.rename_file', false); - - $app['config']->set('lfm.alphanumeric_filename', true); - - $app['config']->set('lfm.alphanumeric_directory', false); - - $app['config']->set('lfm.should_validate_size', false); - - $app['config']->set('lfm.max_image_size', 50000); - $app['config']->set('lfm.max_file_size', 50000); - - $app['config']->set('lfm.should_validate_mime', false); - - $app['config']->set('lfm.valid_image_mimetypes', [ - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/gif', - 'image/svg+xml', - ]); - - $app['config']->set('lfm.valid_file_mimetypes', [ - 'image/jpeg', - 'image/pjpeg', - 'image/png', - 'image/gif', - 'image/svg+xml', - 'application/pdf', - 'text/plain', - ]); - - $app['config']->set('lfm.thumb_img_width', 200); - $app['config']->set('lfm.thumb_img_height', 200); - - $app['config']->set('lfm.file_type_array', [ - 'pdf' => 'Adobe Acrobat', - 'doc' => 'Microsoft Word', - 'docx' => 'Microsoft Word', - 'xls' => 'Microsoft Excel', - 'xlsx' => 'Microsoft Excel', - 'zip' => 'Archive', - 'gif' => 'GIF Image', - 'jpg' => 'JPEG Image', - 'jpeg' => 'JPEG Image', - 'png' => 'PNG Image', - 'ppt' => 'Microsoft PowerPoint', - 'pptx' => 'Microsoft PowerPoint', - ]); - - $app['config']->set('lfm.file_icon_array', [ - 'pdf' => 'fa-file-pdf-o', - 'doc' => 'fa-file-word-o', - 'docx' => 'fa-file-word-o', - 'xls' => 'fa-file-excel-o', - 'xlsx' => 'fa-file-excel-o', - 'zip' => 'fa-file-archive-o', - 'gif' => 'fa-file-image-o', - 'jpg' => 'fa-file-image-o', - 'jpeg' => 'fa-file-image-o', - 'png' => 'fa-file-image-o', - 'ppt' => 'fa-file-powerpoint-o', - 'pptx' => 'fa-file-powerpoint-o', - ]); - - $app['config']->set('lfm.php_ini_overrides', [ - 'memory_limit' => '256M', - ]); - - $app['config']->set('fileapi.path', ['/images/event/']); - $app['config']->set('fileapi.watermark', 'public/img/watermark.png'); - - $app['config']->set('fileapi.default_thumbs', ['S' => '96x96', 'M' => '256x256', 'L' => '480x480']); - - $app['config']->set('fileapi.compress_quality', 90); - } - - public function getResponseByRouteName($route_name, $input = [], $file = []) - { - $response = $this->call('GET', route('unisharp.lfm.' . $route_name), $input, $file); - $data = json_encode($response); - - return $response->getContent(); - } - - protected function getPackageAliases($app) - { - return [ - 'Image' => 'Intervention\Image\Facades\Image', - ]; - } - - public function getStoragedFilePathWithThumb($filename, $filename_s, $working_dir) - { - $files_path['file'] = $this->getStoragedFilePath($filename, $working_dir); - - $files_path['file_s'] = $this->getStoragedFilePath($filename_s, $working_dir); - - return $files_path; - } - - public function getStoragedFilePath($filename, $working_dir) - { - return storage_path(implode(DIRECTORY_SEPARATOR, [ - 'app', - config('lfm.base_directory'), - config('lfm.files_folder_name'), - $working_dir, - $filename, - ])); - } - - public function unlinkFiles(array $files_path) - { - foreach ($files_path as $file_path) { - @unlink($file_path); - } - } - - public function test() - { - $this->assertEquals(1, 1); - } -} diff --git a/tests/TestConfigHandler.php.bak b/tests/TestConfigHandler.php.bak deleted file mode 100644 index ab24b310..00000000 --- a/tests/TestConfigHandler.php.bak +++ /dev/null @@ -1,11 +0,0 @@ -