aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Preview/ProviderV1Adapter.php
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2019-06-04 15:25:25 +0200
committerRobin Appelman <robin@icewind.nl>2019-06-17 14:09:09 +0200
commit615061437422499025e038483504d4ef2004c8e1 (patch)
treebd8752decea5d8c10fea43bdcdd92c38c26ebf30 /lib/private/Preview/ProviderV1Adapter.php
parentf6ad353c7c1176bcaa167051c9f3e118e69f7a20 (diff)
downloadnextcloud-server-615061437422499025e038483504d4ef2004c8e1.tar.gz
nextcloud-server-615061437422499025e038483504d4ef2004c8e1.zip
Add new Provider interface for preview providers
the main difference is passing the `File` object to the provider instead of a `View` + path Old providers will still continue to work as before Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Preview/ProviderV1Adapter.php')
-rw-r--r--lib/private/Preview/ProviderV1Adapter.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/private/Preview/ProviderV1Adapter.php b/lib/private/Preview/ProviderV1Adapter.php
new file mode 100644
index 00000000000..fc7245a5876
--- /dev/null
+++ b/lib/private/Preview/ProviderV1Adapter.php
@@ -0,0 +1,59 @@
+<?php declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Preview;
+
+use OC\Files\View;
+use OCP\Files\File;
+use OCP\Files\FileInfo;
+use OCP\IImage;
+use OCP\Preview\IProvider;
+use OCP\Preview\IProviderV2;
+
+class ProviderV1Adapter implements IProviderV2 {
+ private $providerV1;
+
+ public function __construct(IProvider $providerV1) {
+ $this->providerV1 = $providerV1;
+ }
+
+ public function getMimeType(): string {
+ return $this->providerV1->getMimeType();
+ }
+
+ public function isAvailable(FileInfo $file): bool {
+ return $this->isAvailable($file);
+ }
+
+ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
+ list($view, $path) = $this->getViewAndPath($file);
+ $thumbnail = $this->providerV1->getThumbnail($path, $maxX, $maxY, false, $view);
+ return $thumbnail === false ? null: $thumbnail;
+ }
+
+ private function getViewAndPath(File $file) {
+ $view = new View($file->getParent()->getPath());
+ $path = $file->getName();
+
+ return [$view, $path];
+ }
+
+}