Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2. class Awesome extends League\Flysystem\Adapter\Local {
  3. public function write($path, $contents, League\Flysystem\Config $config) {
  4. $location = $this->applyPathPrefix($path);
  5. $this->ensureDirectory(dirname($location));
  6.  
  7. if (($size = file_put_contents($location, $contents, $this->writeFlags)) === false) {
  8. return false;
  9. }
  10.  
  11. ImageOptimizer::optimize($location, $location);
  12. if(($size = filesize($location)) === false) {
  13. return false;
  14. }
  15.  
  16. $type = 'file';
  17. $result = compact('contents', 'type', 'size', 'path');
  18.  
  19. if ($visibility = $config->get('visibility')) {
  20. $result['visibility'] = $visibility;
  21. $this->setVisibility($path, $visibility);
  22. }
  23.  
  24. return $result;
  25. }
  26.  
  27. public function update($path, $contents, League\Flysystem\Config $config) {
  28. $location = $this->applyPathPrefix($path);
  29. $size = file_put_contents($location, $contents, $this->writeFlags);
  30.  
  31. if ($size === false) {
  32. return false;
  33. }
  34.  
  35. ImageOptimizer::optimize($location, $location);
  36.  
  37. if(($size = filesize($location)) === false) {
  38. return false;
  39. }
  40.  
  41. $type = 'file';
  42.  
  43. $result = compact('type', 'path', 'size', 'contents');
  44.  
  45. if ($mimetype = Util::guessMimeType($path, $contents)) {
  46. $result['mimetype'] = $mimetype;
  47. }
  48.  
  49. return $result;
  50. }
  51. }
  52.  
  53. Route::get('glide/{path}', function($path) {
  54. $server = ServerFactory::create([
  55. 'response' => new LaravelResponseFactory(app('request')),
  56. 'source' => app('filesystem')->disk('public')->getDriver(),
  57. 'cache' => new League\Flysystem\Filesystem(
  58. new Awesome( storage_path('glide') )
  59. )
  60. ]);
  61. return $server->getImageResponse($path, Input::query());
  62. })->where('path', '.+');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement