X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/43830a372fc51a8793199d04a34c3f4ebdfccc7b..refs/pull/3247/head:/app/Uploads/AttachmentService.php diff --git a/app/Uploads/AttachmentService.php b/app/Uploads/AttachmentService.php index c9cd99b38..7974d7ae9 100644 --- a/app/Uploads/AttachmentService.php +++ b/app/Uploads/AttachmentService.php @@ -4,9 +4,9 @@ namespace BookStack\Uploads; use BookStack\Exceptions\FileUploadException; use Exception; -use Illuminate\Contracts\Filesystem\Factory as FileSystem; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Filesystem\Filesystem as FileSystemInstance; +use Illuminate\Contracts\Filesystem\Filesystem as Storage; +use Illuminate\Filesystem\FilesystemManager; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use League\Flysystem\Util; @@ -19,7 +19,7 @@ class AttachmentService /** * AttachmentService constructor. */ - public function __construct(FileSystem $fileSystem) + public function __construct(FilesystemManager $fileSystem) { $this->fileSystem = $fileSystem; } @@ -27,7 +27,7 @@ class AttachmentService /** * Get the storage that will be used for storing files. */ - protected function getStorageDisk(): FileSystemInstance + protected function getStorageDisk(): Storage { return $this->fileSystem->disk($this->getStorageDiskName()); } @@ -216,7 +216,7 @@ class AttachmentService $storage = $this->getStorageDisk(); $basePath = 'uploads/files/' . date('Y-m-M') . '/'; - $uploadFileName = Str::random(16) . '.' . $uploadedFile->getClientOriginalExtension(); + $uploadFileName = Str::random(16) . '-' . $uploadedFile->getClientOriginalExtension(); while ($storage->exists($this->adjustPathForStorageDisk($basePath . $uploadFileName))) { $uploadFileName = Str::random(3) . $uploadFileName; } @@ -233,4 +233,12 @@ class AttachmentService return $attachmentPath; } + + /** + * Get the file validation rules for attachments. + */ + public function getFileValidationRules(): array + { + return ['file', 'max:' . (config('app.upload_limit') * 1000)]; + } }