diff --git a/src/LfmItem.php b/src/LfmItem.php index 74d133af..65cc9049 100644 --- a/src/LfmItem.php +++ b/src/LfmItem.php @@ -9,14 +9,17 @@ class LfmItem { private $lfm; private $helper; + private $isDirectory; + private $mimeType = null; private $columns = ['name', 'url', 'time', 'icon', 'is_file', 'is_image', 'thumb_url']; public $attributes = []; - public function __construct(LfmPath $lfm, Lfm $helper) + public function __construct(LfmPath $lfm, Lfm $helper, $isDirectory = false) { $this->lfm = $lfm->thumb(false); $this->helper = $helper; + $this->isDirectory = $isDirectory; } public function __get($var_name) @@ -50,7 +53,7 @@ public function path($type = 'absolute') public function isDirectory() { - return $this->lfm->isDirectory(); + return $this->isDirectory; } public function isFile() @@ -66,11 +69,7 @@ public function isFile() */ public function isImage() { - if (!$this->isDirectory()) { - return Str::startsWith($this->mimeType(), 'image'); - } - - return false; + return $this->isFile() && Str::startsWith($this->mimeType(), 'image'); } /** @@ -79,14 +78,13 @@ public function isImage() * @param mixed $file Real path of a file or instance of UploadedFile. * @return string */ - // TODO: uploaded file public function mimeType() { - // if ($file instanceof UploadedFile) { - // return $file->getMimeType(); - // } + if (is_null($this->mimeType)) { + $this->mimeType = $this->lfm->mimeType(); + } - return $this->lfm->mimeType(); + return $this->mimeType; } public function extension() diff --git a/src/LfmPath.php b/src/LfmPath.php index a4ff93af..7db5e767 100644 --- a/src/LfmPath.php +++ b/src/LfmPath.php @@ -70,7 +70,7 @@ public function path($type = 'storage') } elseif ($type == 'storage') { // storage: files/{user_slug} // storage on windows: files\{user_slug} - return $this->translateToOsPath($this->path('url')); + return str_replace(Lfm::DS, $this->helper->ds(), $this->path('url')); } else { // absolute: /var/www/html/project/storage/app/files/{user_slug} // absolute on windows: C:\project\storage\app\files\{user_slug} @@ -83,11 +83,6 @@ public function translateToLfmPath($path) return str_replace($this->helper->ds(), Lfm::DS, $path); } - public function translateToOsPath($path) - { - return str_replace(Lfm::DS, $this->helper->ds(), $path); - } - public function url() { return $this->storage->url($this->path('url')); @@ -96,7 +91,7 @@ public function url() public function folders() { $all_folders = array_map(function ($directory_path) { - return $this->pretty($directory_path); + return $this->pretty($directory_path, true); }, $this->storage->directories()); $folders = array_filter($all_folders, function ($directory) { @@ -115,11 +110,12 @@ public function files() return $this->sortByColumn($files); } - public function pretty($item_path) + public function pretty($item_path, $isDirectory = false) { return Container::getInstance()->makeWith(LfmItem::class, [ 'lfm' => (clone $this)->setName($this->helper->getNameFromPath($item_path)), - 'helper' => $this->helper + 'helper' => $this->helper, + 'isDirectory' => $isDirectory ]); }