Beispiel #1
0
 /**
  * Retrieves the file based on the given ID
  *
  * @param int $fileId
  *
  * @return File
  */
 private function getFile($fileId)
 {
     try {
         /** @type File $file */
         $file = $this->downloadService->getResourceFromId($fileId);
     } catch (ServiceException $exception) {
         $file = false;
     }
     return $file;
 }
Beispiel #2
0
 /**
  * Generates the download data
  *
  * @param int $fileId the ID of the file of which we need a large preview of
  * @param string|null $filename
  *
  * @return array|false
  */
 private function getDownload($fileId, $filename)
 {
     /** @type File $file */
     $file = $this->downloadService->getResourceFromId($fileId);
     $this->configService->validateMimeType($file->getMimeType());
     $download = $this->downloadService->downloadFile($file);
     if (is_null($filename)) {
         $filename = $file->getName();
     }
     $download['name'] = $filename;
     return $download;
 }
Beispiel #3
0
 /**
  * Downloads the file associated with a token
  *
  * @param File $file
  * @param string|null $filename
  *
  * @return ImageResponse|RedirectResponse
  */
 private function downloadFile($file, $filename)
 {
     try {
         $download = $this->downloadService->downloadFile($file);
         if (is_null($filename)) {
             $filename = $file->getName();
         }
         $download['name'] = $filename;
         return new ImageResponse($download);
     } catch (ServiceException $exception) {
         $url = $this->urlGenerator->linkToRoute($this->appName . '.page.error_page', ['message' => $exception->getMessage(), 'code' => Http::STATUS_NOT_FOUND]);
         return new RedirectResponse($url);
     }
 }
Beispiel #4
0
 /**
  * @param File $file
  * @param bool $animatedPreview
  * @param int $width
  * @param int $height
  * @param bool $keepAspect
  * @param bool $base64Encode
  *
  * @return array
  */
 private function getPreviewData($file, $animatedPreview, $width, $height, $keepAspect, $base64Encode)
 {
     $status = Http::STATUS_OK;
     if ($this->previewService->isPreviewRequired($file, $animatedPreview)) {
         $type = 'preview';
         $preview = $this->previewService->createPreview($file, $width, $height, $keepAspect, $base64Encode);
     } else {
         $type = 'download';
         $preview = $this->downloadService->downloadFile($file, $base64Encode);
     }
     if (!$preview) {
         list($preview, $status, $type) = $this->getErrorData();
     }
     return [$preview, $status, $type];
 }
 /**
  * @param $file
  * @param $previewRequired
  * @param $width
  * @param $height
  * @param $keepAspect
  * @param $base64Encode
  *
  * @return array
  */
 private function getPreviewData($file, $previewRequired, $width, $height, $keepAspect, $base64Encode)
 {
     $status = Http::STATUS_OK;
     if ($previewRequired) {
         $type = 'preview';
         $preview = $this->previewService->createPreview($file, $width, $height, $keepAspect, $base64Encode);
     } else {
         $type = 'download';
         $preview = $this->downloadService->downloadFile($file, $base64Encode);
     }
     if (!$preview) {
         $type = 'error';
         $status = Http::STATUS_INTERNAL_SERVER_ERROR;
         $preview = null;
     }
     return [$preview, $status, $type];
 }
 /**
  * Mocks DownloadService->downloadFile
  *
  * @param object|\PHPUnit_Framework_MockObject_MockObject $file
  * @param array $download
  */
 private function mockDownloadFile($file, $download)
 {
     $this->downloadService->expects($this->once())->method('downloadFile')->with($this->equalTo($file))->willReturn($download);
 }
 public function testDownloadNonExistentFile()
 {
     $file = $this->mockBadFile(12345);
     $downloadResponse = $this->service->downloadFile($file);
     $this->assertFalse($downloadResponse);
 }
 /**
  * @expectedException \OCA\GalleryPlus\Service\NotFoundServiceException
  */
 public function testDownloadNonExistentFile()
 {
     $file = $this->mockBadFile(12345);
     $this->service->downloadFile($file);
 }
 /**
  * @param $file
  * @param $base64Encode
  * @param $preview
  */
 private function mockDownloadFile($file, $base64Encode, $preview)
 {
     $this->downloadService->expects($this->once())->method('downloadFile')->with($this->equalTo($file), $this->equalTo($base64Encode))->willReturn($preview);
 }