Пример #1
1
 /**
  * Return the URL for the file.
  *
  * @param array $attributes
  * @param null  $secure
  * @return string
  */
 public function url(array $attributes = [], $secure = null)
 {
     if ($secure === null) {
         $secure = $this->request->isSecure();
     }
     return $this->url->to($this->object->publicPath(), $attributes, $secure);
 }
Пример #2
0
 /**
  * Chunk the request into parts as
  * desired by the request range header.
  *
  * @param Response      $response
  * @param FileInterface $file
  */
 protected function chunk(Response $response, FileInterface $file)
 {
     $size = $chunkStart = $file->getSize();
     $end = $chunkEnd = $size;
     $response->headers->set('Content-length', $size);
     $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     if (!($range = array_get($_SERVER, 'HTTP_RANGE'))) {
         return;
     }
     list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
     if (strpos($range, ',') !== false) {
         $response->setStatusCode(416, 'Requested Range Not Satisfiable');
         $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     }
     if ($range == '-') {
         $chunkStart = $size - substr($range, 1);
     } else {
         $range = explode('-', $range);
         $chunkStart = $range[0];
         $chunkEnd = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size;
     }
     $chunkEnd = $chunkEnd > $end ? $end : $chunkEnd;
     if ($chunkStart > $chunkEnd || $chunkStart > $size || $chunkEnd >= $size) {
         $response->setStatusCode(416, 'Requested Range Not Satisfiable');
         $response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
     }
 }
Пример #3
0
 /**
  * Handle the command.
  *
  * @param MountManager $manager
  * @return File
  */
 public function handle(MountManager $manager)
 {
     try {
         return $manager->get($this->file->location());
     } catch (\Exception $e) {
         return null;
     }
 }
Пример #4
0
 /**
  * Handle the command.
  *
  * @param Repository $config
  * @return int|null|string
  */
 public function handle(Repository $config)
 {
     foreach ($config->get('anomaly.module.files::mimes.types') as $type => $extensions) {
         if (in_array($this->file->getExtension(), $extensions)) {
             return $type;
         }
     }
     return null;
 }
Пример #5
0
 /**
  * Make the response.
  *
  * @param FileInterface $file
  * @return Response
  */
 public function make(FileInterface $file)
 {
     // Start the response.
     $response = $this->response->make();
     $response->headers->set('Etag', $file->etag());
     $response->headers->set('Content-Type', $file->getMimetype());
     $response->headers->set('Last-Modified', $file->lastModified()->setTimezone('GMT')->format('D, d M Y H:i:s'));
     $response->setTtl(3600);
     return $response;
 }
Пример #6
0
 /**
  * Make the response.
  *
  * @param FileInterface $file
  * @return Response
  */
 public function make(FileInterface $file)
 {
     // Start the response.
     $response = $this->response->make();
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Etag', $file->hash());
     $response->headers->set('Content-Length', $file->getSize());
     $response->headers->set('Content-Type', $file->getMimetype());
     $response->headers->set('Cache-Control', 'public,max-age=300,s-maxage=900');
     // Should be configurable
     $response->headers->set('Last-Modified', $file->lastModified()->setTimezone('GMT')->format('D, d M Y H:i:s'));
     return $response;
 }
Пример #7
0
 /**
  * Catch calls to fields on
  * the file's related entry.
  *
  * @param string $key
  * @return mixed
  */
 public function __get($key)
 {
     $entry = $this->object->getEntry();
     if ($entry && $entry->hasField($key)) {
         return (new Decorator())->decorate($entry)->{$key};
     }
     return parent::__get($key);
 }
Пример #8
0
 /**
  * Handle the command.
  *
  * @param Image $image
  * @return Image
  */
 public function handle(Image $image)
 {
     return $image->make($this->file->location())->setOutput('image');
 }
Пример #9
0
 /**
  * Delete a file.
  *
  * @param FileInterface|EloquentModel $file
  * @return bool
  */
 public function delete(FileInterface $file)
 {
     return $file->delete();
 }
Пример #10
0
 /**
  * Handle the command.
  *
  * @param MountManager $manager
  * @return File
  */
 public function handle(MountManager $manager)
 {
     return $manager->get($this->file->location());
 }