Skip to content

Commit 882eb39

Browse files
committed
Small refactoring
1 parent 4c7333e commit 882eb39

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

src/controllers/FolderController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,21 @@ public function getFolders()
5555
public function getAddfolder()
5656
{
5757
$folder_name = parent::translateFromUtf8(trim(request('name')));
58-
5958
$path = parent::getCurrentPath($folder_name);
6059

6160
if (empty($folder_name)) {
6261
return parent::error('folder-name');
63-
} elseif (File::exists($path)) {
62+
}
63+
64+
if (File::exists($path)) {
6465
return parent::error('folder-exist');
65-
} elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
66-
return parent::error('folder-alnum');
67-
} else {
68-
parent::createFolderByPath($path);
66+
}
6967

70-
return parent::$success_response;
68+
if (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
69+
return parent::error('folder-alnum');
7170
}
71+
72+
parent::createFolderByPath($path);
73+
return parent::$success_response;
7274
}
7375
}

src/controllers/ItemsController.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,29 @@ public function getItems()
3232

3333
private function getView()
3434
{
35-
$view_type = 'grid';
36-
$show_list = request('show_list');
37-
38-
if ($show_list === '1') {
39-
$view_type = 'list';
40-
} elseif (is_null($show_list)) {
41-
$type_key = parent::currentLfmType();
42-
$startup_view = config('lfm.' . $type_key . 's_startup_view');
43-
44-
if (in_array($startup_view, ['list', 'grid'])) {
45-
$view_type = $startup_view;
46-
}
35+
$view_type = request('show_list');
36+
37+
if (null === $view_type) {
38+
return $this->composeViewName($this->getStartupViewFromConfig());
4739
}
4840

49-
return 'laravel-filemanager::' . $view_type . '-view';
41+
$view_mapping = [
42+
'0' => 'grid',
43+
'1' => 'list'
44+
];
45+
46+
return $this->composeViewName($view_mapping[$view_type]);
47+
}
48+
49+
private function composeViewName($view_type = 'grid')
50+
{
51+
return "laravel-filemanager::$view_type-view";
52+
}
53+
54+
private function getStartupViewFromConfig($default = 'grid')
55+
{
56+
$type_key = parent::currentLfmType();
57+
$startup_view = config('lfm.' . $type_key . 's_startup_view', $default);
58+
return $startup_view;
5059
}
5160
}

src/controllers/RedirectController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function __construct()
1717
{
1818
$delimiter = config('lfm.url_prefix') . '/';
1919
$url = urldecode(request()->url());
20-
// dd($delimiter);
2120
$external_path = substr($url, strpos($url, $delimiter) + strlen($delimiter));
2221

2322
$this->file_path = base_path(config('lfm.base_directory', 'public') . '/' . $external_path);

src/controllers/ResizeController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function getResize()
2727

2828
$scaled = false;
2929

30+
// FIXME size should be configurable
3031
if ($original_width > 600) {
3132
$ratio = 600 / $original_width;
3233
$width = $original_width * $ratio;

0 commit comments

Comments
 (0)