Skip to content

Commit d4b30a1

Browse files
committed
remove FileApi integration
1 parent 1380341 commit d4b30a1

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

src/Lfm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public function __construct(Config $config = null, Request $request = null)
2121

2222
public function getStorage($storage_path)
2323
{
24-
if ($this->config->get('lfm.driver') == 'storage') {
25-
return new LfmStorageRepository($storage_path);
24+
if ($this->config->get('lfm.driver') === 'storage') {
25+
return new LfmStorageRepository($storage_path, $this->config->get('lfm.disk'));
2626
} else {
2727
return new LfmFileRepository($storage_path);
2828
}
@@ -230,7 +230,7 @@ public function shouldSetStorageRoute()
230230

231231
$storage_root = $this->getStorage('/')->rootPath();
232232

233-
if ($driver === 'storage' && (ends_with($storage_root, 'public') && ends_with($storage_root, 'public/'))) {
233+
if ($driver === 'storage' && (ends_with($storage_root, 'public') || ends_with($storage_root, 'public/'))) {
234234
return false;
235235
}
236236

src/LfmFileRepository.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ public function directoryIsEmpty()
8282

8383
public function save($file, $new_filename)
8484
{
85-
$result_filename = $new_filename . '.' . $file->getClientOriginalExtension();
86-
$new_filepath = $this->path . '/' . $result_filename;
87-
File::move($file->getRealPath(), $new_filepath);
88-
89-
return $result_filename;
85+
File::move($file->getRealPath(), $this->path . '/' . $new_filename);
9086
}
9187
}

src/LfmPath.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,28 @@ private function getNewName($file)
255255
$new_filename = preg_replace('/[^A-Za-z0-9\-\']/', '_', $new_filename);
256256
}
257257

258+
$extension = $file->getClientOriginalExtension();
259+
260+
if ($extension) {
261+
$new_filename .= '.' . $extension;
262+
}
263+
258264
return $new_filename;
259265
}
260266

261267
private function saveFile($file, $new_filename)
262268
{
263269
$should_create_thumbnail = $this->shouldCreateThumb($file);
264270

265-
$filename = $this->setName(null)->thumb(false)->storage->save($file, $new_filename);
271+
$this->setName(null)->thumb(false)->storage->save($file, $new_filename);
266272

267-
chmod($this->setName($filename)->thumb(false)->path('absolute'), config('lfm.create_file_mode', 0644));
273+
chmod($this->setName($new_filename)->thumb(false)->path('absolute'), config('lfm.create_file_mode', 0644));
268274

269275
if ($should_create_thumbnail) {
270-
$this->makeThumbnail($filename);
276+
$this->makeThumbnail($new_filename);
271277
}
272278

273-
return $filename;
279+
return $new_filename;
274280
}
275281

276282
public function makeThumbnail($filename)

src/LfmStorageRepository.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
class LfmStorageRepository implements RepositoryContract
99
{
10-
const DISK_NAME = 'local'; // config('lfm.disk')
10+
private $disk_name;
1111

1212
private $disk;
1313

1414
private $path;
1515

16-
public function __construct($storage_path)
16+
public function __construct($storage_path, $disk_name)
1717
{
18-
$this->disk = Storage::disk(self::DISK_NAME);
18+
$this->disk_name = $disk_name;
19+
$this->disk = Storage::disk($this->disk_name);
1920
$this->path = $storage_path;
2021
}
2122

@@ -88,9 +89,7 @@ public function directoryIsEmpty()
8889

8990
public function save($file, $new_filename)
9091
{
91-
$new_filename = (new FileApi($this->path))->thumbs([])->save($file, $new_filename);
92-
93-
return $new_filename;
92+
$this->disk->putFileAs($this->path, $file, $new_filename);
9493
}
9594

9695
private function insertSuffix($suffix, $file_name)

src/config/lfm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989

9090
'driver' => 'file',
9191

92+
'disk' => 'local',
93+
9294
'rename_file' => false,
9395

9496
'alphanumeric_filename' => false,

src/controllers/UploadController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use UniSharp\LaravelFilemanager\Events\ImageIsUploading;
1010
use UniSharp\LaravelFilemanager\Events\ImageWasUploaded;
1111
use UniSharp\LaravelFilemanager\Lfm;
12-
use Unisharp\FileApi\FileApi;
1312

1413
class UploadController extends LfmController
1514
{

0 commit comments

Comments
 (0)