You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @author Julius Härtl <jus@bitgrid.net>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Preview;
  26. use OC\Files\View;
  27. use OCP\Files\File;
  28. use OCP\Files\FileInfo;
  29. use OCP\IImage;
  30. use OCP\Preview\IProvider;
  31. use OCP\Preview\IProviderV2;
  32. class ProviderV1Adapter implements IProviderV2 {
  33. private $providerV1;
  34. public function __construct(IProvider $providerV1) {
  35. $this->providerV1 = $providerV1;
  36. }
  37. public function getMimeType(): string {
  38. return (string)$this->providerV1->getMimeType();
  39. }
  40. public function isAvailable(FileInfo $file): bool {
  41. return (bool)$this->providerV1->isAvailable($file);
  42. }
  43. public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
  44. list($view, $path) = $this->getViewAndPath($file);
  45. $thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view);
  46. return $thumbnail === false ? null: $thumbnail;
  47. }
  48. private function getViewAndPath(File $file) {
  49. $view = new View($file->getParent()->getPath());
  50. $path = $file->getName();
  51. return [$view, $path];
  52. }
  53. }