Skip to content

Commit 0db6233

Browse files
committed
remove redundant code
1 parent c16ca8c commit 0db6233

File tree

4 files changed

+20
-29
lines changed

4 files changed

+20
-29
lines changed

src/Lfm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getStorage($storage_path)
3030

3131
public function input($key)
3232
{
33-
return $this->request->input($key);
33+
return $this->translateFromUtf8($this->request->input($key));
3434
}
3535

3636
/**

src/LfmPath.php

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function appendPathToFile($path, $is_windows = false)
100100
return $path;
101101
}
102102

103-
public function folders($column = null)
103+
public function folders()
104104
{
105105
$all_folders = array_map(function ($directory_path) {
106106
return $this->get($directory_path);
@@ -110,16 +110,16 @@ public function folders($column = null)
110110
return $directory->name !== $this->helper->getThumbFolderName();
111111
});
112112

113-
return $this->sortByColumn($folders, $column);
113+
return $this->sortByColumn($folders);
114114
}
115115

116-
public function files($column = null)
116+
public function files()
117117
{
118118
$files = array_map(function ($file_path) {
119119
return $this->get($file_path);
120120
}, $this->storage->files());
121121

122-
return $this->sortByColumn($files, $column);
122+
return $this->sortByColumn($files);
123123
}
124124

125125
public function get($item_path)
@@ -168,15 +168,12 @@ public function normalizeWorkingDir()
168168
* @param mixed $sort_type Alphabetic or time.
169169
* @return array of object
170170
*/
171-
public function sortByColumn($arr_items, $key_to_sort = null)
171+
public function sortByColumn($arr_items)
172172
{
173-
if (is_null($key_to_sort)) {
174-
$sort_type = $this->helper->input('sort_type');
175-
if (!$sort_type || $sort_type == 'alphabetic') {
176-
$key_to_sort = 'name';
177-
} else {
178-
$key_to_sort = 'time';
179-
}
173+
if ($this->helper->input('sort_type') === 'alphabetic') {
174+
$key_to_sort = 'name';
175+
} else {
176+
$key_to_sort = 'time';
180177
}
181178

182179
uasort($arr_items, function ($a, $b) use ($key_to_sort) {
@@ -200,7 +197,7 @@ public function upload($file)
200197

201198
event(new ImageIsUploading($new_file_path));
202199
try {
203-
$new_filename = $this->save($file, $new_filename);
200+
$new_filename = $this->saveFile($file, $new_filename);
204201
} catch (\Exception $e) {
205202
\Log::info($e);
206203
return $this->error('invalid');
@@ -229,11 +226,8 @@ private function uploadValidator($file)
229226
return $this->error('file-exist');
230227
}
231228

232-
$mimetype = $file->getMimeType();
233-
234-
$type_key = $this->helper->currentLfmType();
235-
236229
if (config('lfm.should_validate_mime', false)) {
230+
$mimetype = $file->getMimeType();
237231
if (false === in_array($mimetype, $this->helper->availableMimeTypes())) {
238232
return $this->error('mime') . $mimetype;
239233
}
@@ -263,9 +257,10 @@ private function getNewName($file)
263257
return $new_filename;
264258
}
265259

266-
private function save($file, $new_filename)
260+
private function saveFile($file, $new_filename)
267261
{
268-
$should_create_thumbnail = $this->isUploadingImage($file) && $this->shouldCreateThumb($file);
262+
$should_create_thumbnail = $this->shouldCreateThumb($file);
263+
269264
$filename = $this->setName(null)->thumb(false)->storage->save($file, $new_filename);
270265

271266
chmod($this->setName($filename)->thumb(false)->path('absolute'), config('lfm.create_file_mode', 0644));
@@ -288,13 +283,9 @@ public function makeThumbnail($filename)
288283
->save($this->thumb(true)->setName($filename)->path('absolute'));
289284
}
290285

291-
private function isUploadingImage($file)
292-
{
293-
return starts_with($file->getMimeType(), 'image');
294-
}
295-
296286
private function shouldCreateThumb($file)
297287
{
298-
return !in_array($file->getMimeType(), ['image/gif', 'image/svg+xml']);
288+
return starts_with($file->getMimeType(), 'image')
289+
&& !in_array($file->getMimeType(), ['image/gif', 'image/svg+xml']);
299290
}
300291
}

src/controllers/FolderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getFolders()
3737
*/
3838
public function getAddfolder()
3939
{
40-
$folder_name = $this->helper->translateFromUtf8(trim(request('name')));
40+
$folder_name = $this->helper->input('name');
4141

4242
if (empty($folder_name)) {
4343
return parent::error('folder-name');

src/controllers/RenameController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class RenameController extends LfmController
1111
{
1212
public function getRename()
1313
{
14-
$old_name = $this->helper->translateFromUtf8(request('file'));
15-
$new_name = $this->helper->translateFromUtf8(trim(request('new_name')));
14+
$old_name = $this->helper->input('file');
15+
$new_name = $this->helper->input('new_name');
1616

1717
$old_file = $this->lfm->get($old_name);
1818

0 commit comments

Comments
 (0)