Example #1
0
 /**
  * Returns the file of which a preview will be generated
  *
  * @param int $fileId
  *
  * @return array<File|int|null>
  */
 private function getFile($fileId)
 {
     $status = Http::STATUS_OK;
     try {
         /** @type File $file */
         $file = $this->previewService->getResourceFromId($fileId);
         $this->configService->validateMimeType($file->getMimeType());
     } catch (ServiceException $exception) {
         $file = null;
         $status = $this->getHttpStatusCode($exception);
     }
     return [$file, $status];
 }
Example #2
0
 /**
  * Returns either a generated preview, the file as-is or an empty object
  *
  * @param int $fileId
  * @param int $width
  * @param int $height
  * @param bool $keepAspect
  * @param bool $animatedPreview
  * @param bool $base64Encode
  *
  * @return array<string,\OC_Image|string>
  *
  * @throws NotFoundServiceException
  */
 private function getData($fileId, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false)
 {
     try {
         /** @type File $file */
         $file = $this->previewService->getResourceFromId($fileId);
         if (!is_null($file)) {
             $data = $this->getPreviewData($file, $animatedPreview, $width, $height, $keepAspect, $base64Encode);
         } else {
             // Uncaught problem, should never reach this point...
             $data = $this->getErrorData(Http::STATUS_NOT_FOUND);
         }
     } catch (ServiceException $exception) {
         $file = null;
         $data = $this->getExceptionData($exception);
     }
     array_unshift($data, $file);
     return $data;
 }