ProviderV1Adapter.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Preview;
  8. use OC\Files\View;
  9. use OCP\Files\File;
  10. use OCP\Files\FileInfo;
  11. use OCP\IImage;
  12. use OCP\Preview\IProvider;
  13. use OCP\Preview\IProviderV2;
  14. class ProviderV1Adapter implements IProviderV2 {
  15. private $providerV1;
  16. public function __construct(IProvider $providerV1) {
  17. $this->providerV1 = $providerV1;
  18. }
  19. public function getMimeType(): string {
  20. return (string)$this->providerV1->getMimeType();
  21. }
  22. public function isAvailable(FileInfo $file): bool {
  23. return (bool)$this->providerV1->isAvailable($file);
  24. }
  25. public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
  26. [$view, $path] = $this->getViewAndPath($file);
  27. $thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view);
  28. return $thumbnail === false ? null: $thumbnail;
  29. }
  30. private function getViewAndPath(File $file) {
  31. $view = new View(dirname($file->getPath()));
  32. $path = $file->getName();
  33. return [$view, $path];
  34. }
  35. }