You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
798 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace CustomHandlers\Actions;
  3. use Illuminate\Support\Facades\File;
  4. use Illuminate\Support\Str;
  5. use Mimey\MimeTypes;
  6. /**
  7. *
  8. *
  9. *
  10. */
  11. class FileDownload extends ActionHandler
  12. {
  13. public function run()
  14. {
  15. if (isset($this->data->enclosure) && isset($this->data->enclosure->attributes()->url)) {
  16. // get mimes
  17. $mimes = new MimeTypes();
  18. $extension = $mimes->getExtension($this->data->enclosure->attributes()->type);
  19. // if extension valid
  20. if ($extension) {
  21. $filename = Str::slug($this->data->title).'.'.$extension;
  22. Storage::download($this->data->enclosure->attributes()->url)->put($filename);
  23. } else {
  24. // @TODO what you do
  25. }
  26. }
  27. }
  28. }