diff --git a/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php index 8b314dbc..6d7f5afc 100644 --- a/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php +++ b/app/Classes/Modules/Documents/ControllersLogic/RenderDocumentLogic.php @@ -54,17 +54,20 @@ class RenderDocumentLogic extends AbstractControllerLogic $this->canRenderDocument->passes(); - // if(!Storage::disk('documents')->exists($file)) - // { - // throw new ResourceNotFoundException(); - // } - - // return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); - if(!Storage::disk('s3')->exists($file)) - { - throw new ResourceNotFoundException(); + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver == 's3'){ + if(!Storage::disk('s3')->exists($file)) + { + throw new ResourceNotFoundException(); + } + return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); + } + else{ + if(!Storage::disk('documents')->exists($file)) + { + throw new ResourceNotFoundException(); + } + return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); } - - return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); } } diff --git a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php index 8f73dc1b..3f862417 100644 --- a/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php +++ b/app/Classes/Modules/Documents/DataTransferObjects/DocumentObject.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Documents\DataTransferObjects; use App\Classes\General\Interfaces\DataTransferObject; use App\Classes\Modules\Documents\Services\ConvertsBase64ToFile; +use Illuminate\Support\Facades\Storage; class DocumentObject implements DataTransferObject { @@ -72,9 +73,14 @@ class DocumentObject implements DataTransferObject */ public function getFiles(): array { - return (new ConvertsBase64ToFile($this->path))->convert($this->files); + $filePath = $this->path; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver == 's3'){ + $filePath = 'documents/'.$this->path; + } + return (new ConvertsBase64ToFile($filePath))->convert($this->files); } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php index 6e7f17f5..9f094065 100644 --- a/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php +++ b/app/Classes/Modules/Documents/Services/ConvertsBase64ToFile.php @@ -99,15 +99,17 @@ class ConvertsBase64ToFile */ private function generateFile(FileObject $file, string $suffix = '') { - // $filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension(); - - // Storage::disk('documents')->put($filePath, $file->getDecodedData()); - - // return $filePath; - - $filePath = 'localhost/'.$file->getFileName().$suffix.'.'.$file->getExtension(); - Storage::put($filePath, $file->getDecodedData(), 's3'); - return $filePath; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver == 's3'){ + $filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension(); + Storage::put($filePath, $file->getDecodedData(), 's3'); + return $filePath; + } + else{ + $filePath = $this->path.'/'.$file->getFileName().$suffix.'.'.$file->getExtension(); + Storage::disk('documents')->put($filePath, $file->getDecodedData()); + return $filePath; + } } /**