mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-25 17:57:28 +08:00
23f90ed6b4
Also added tests to cover local_secure image storage. Fixes #725
46 lines
1.0 KiB
PHP
46 lines
1.0 KiB
PHP
<?php namespace BookStack\Services;
|
|
|
|
use Illuminate\Contracts\Filesystem\Factory as FileSystem;
|
|
use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance;
|
|
|
|
class UploadService
|
|
{
|
|
|
|
/**
|
|
* @var FileSystem
|
|
*/
|
|
protected $fileSystem;
|
|
|
|
|
|
/**
|
|
* FileService constructor.
|
|
* @param $fileSystem
|
|
*/
|
|
public function __construct(FileSystem $fileSystem)
|
|
{
|
|
$this->fileSystem = $fileSystem;
|
|
}
|
|
|
|
/**
|
|
* Get the storage that will be used for storing images.
|
|
* @return FileSystemInstance
|
|
*/
|
|
protected function getStorage()
|
|
{
|
|
$storageType = config('filesystems.default');
|
|
return $this->fileSystem->disk($storageType);
|
|
}
|
|
|
|
/**
|
|
* Check whether or not a folder is empty.
|
|
* @param $path
|
|
* @return bool
|
|
*/
|
|
protected function isFolderEmpty($path)
|
|
{
|
|
$files = $this->getStorage()->files($path);
|
|
$folders = $this->getStorage()->directories($path);
|
|
return (count($files) === 0 && count($folders) === 0);
|
|
}
|
|
}
|