aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Preview
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/Preview')
-rw-r--r--lib/public/Preview/BeforePreviewFetchedEvent.php83
-rw-r--r--lib/public/Preview/IMimeIconProvider.php22
-rw-r--r--lib/public/Preview/IProvider.php44
-rw-r--r--lib/public/Preview/IProviderV2.php43
-rw-r--r--lib/public/Preview/IVersionedPreviewFile.php25
5 files changed, 217 insertions, 0 deletions
diff --git a/lib/public/Preview/BeforePreviewFetchedEvent.php b/lib/public/Preview/BeforePreviewFetchedEvent.php
new file mode 100644
index 00000000000..8ab875070d9
--- /dev/null
+++ b/lib/public/Preview/BeforePreviewFetchedEvent.php
@@ -0,0 +1,83 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Preview;
+
+use OCP\Files\Node;
+use OCP\IPreview;
+
+/**
+ * Emitted before a file preview is being fetched.
+ *
+ * It can be used to block preview rendering by throwing a ``OCP\Files\NotFoundException``
+ *
+ * @since 25.0.1
+ * @since 28.0.0 the constructor arguments ``$width``, ``$height``, ``$crop`` and ``$mode`` are no longer nullable.
+ * @since 31.0.0 the constructor arguments ``$mimeType`` was added
+ */
+class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event {
+ /**
+ * @since 25.0.1
+ */
+ public function __construct(
+ private Node $node,
+ /** @deprecated 28.0.0 passing null is deprecated **/
+ private ?int $width = null,
+ /** @deprecated 28.0.0 passing null is deprecated **/
+ private ?int $height = null,
+ /** @deprecated 28.0.0 passing null is deprecated **/
+ private ?bool $crop = null,
+ /** @deprecated 28.0.0 passing null is deprecated **/
+ private ?string $mode = null,
+ private ?string $mimeType = null,
+ ) {
+ parent::__construct();
+ }
+
+ /**
+ * @since 25.0.1
+ */
+ public function getNode(): Node {
+ return $this->node;
+ }
+
+ /**
+ * @since 28.0.0
+ */
+ public function getWidth(): ?int {
+ return $this->width;
+ }
+
+ /**
+ * @since 28.0.0
+ */
+ public function getHeight(): ?int {
+ return $this->height;
+ }
+
+ /**
+ * @since 28.0.0
+ */
+ public function isCrop(): ?bool {
+ return $this->crop;
+ }
+
+ /**
+ * @since 28.0.0
+ * @return null|IPreview::MODE_FILL|IPreview::MODE_COVER
+ */
+ public function getMode(): ?string {
+ return $this->mode;
+ }
+
+ /**
+ * @since 31.0.0
+ */
+ public function getMimeType(): ?string {
+ return $this->mimeType;
+ }
+}
diff --git a/lib/public/Preview/IMimeIconProvider.php b/lib/public/Preview/IMimeIconProvider.php
new file mode 100644
index 00000000000..4a407f48577
--- /dev/null
+++ b/lib/public/Preview/IMimeIconProvider.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Preview;
+
+/**
+ * Interface IMimeIconProvider
+ *
+ * @since 28.0.0
+ */
+interface IMimeIconProvider {
+ /**
+ * Get the URL to the icon for the given mime type
+ * Used by the preview provider to show a mime icon
+ * if no preview is available.
+ * @since 28.0.0
+ */
+ public function getMimeIconUrl(string $mime): ?string;
+}
diff --git a/lib/public/Preview/IProvider.php b/lib/public/Preview/IProvider.php
new file mode 100644
index 00000000000..b06acfbbe5d
--- /dev/null
+++ b/lib/public/Preview/IProvider.php
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCP\Preview;
+
+/**
+ * Interface IProvider
+ *
+ * @since 8.1.0
+ * @deprecated 17.0.0 use IProviderV2 instead
+ */
+interface IProvider {
+ /**
+ * @return string Regex with the mimetypes that are supported by this provider
+ * @since 8.1.0
+ */
+ public function getMimeType();
+
+ /**
+ * Check if a preview can be generated for $path
+ *
+ * @param \OCP\Files\FileInfo $file
+ * @return bool
+ * @since 8.1.0
+ */
+ public function isAvailable(\OCP\Files\FileInfo $file);
+
+ /**
+ * get thumbnail for file at path $path
+ *
+ * @param string $path Path of file
+ * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param bool $scalingup Disable/Enable upscaling of previews
+ * @param \OC\Files\View $fileview fileview object of user folder
+ * @return bool|\OCP\IImage false if no preview was generated
+ * @since 8.1.0
+ */
+ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
+}
diff --git a/lib/public/Preview/IProviderV2.php b/lib/public/Preview/IProviderV2.php
new file mode 100644
index 00000000000..da52f6a7946
--- /dev/null
+++ b/lib/public/Preview/IProviderV2.php
@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Preview;
+
+use OCP\Files\File;
+use OCP\Files\FileInfo;
+use OCP\IImage;
+
+/**
+ * @since 17.0.0
+ */
+interface IProviderV2 {
+ /**
+ * @return string Regex with the mimetypes that are supported by this provider
+ * @since 17.0.0
+ */
+ public function getMimeType(): string;
+
+ /**
+ * Check if a preview can be generated for $path
+ *
+ * @param FileInfo $file
+ * @return bool
+ * @since 17.0.0
+ */
+ public function isAvailable(FileInfo $file): bool;
+
+ /**
+ * get thumbnail for file at path $path
+ *
+ * @param File $file
+ * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image
+ * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image
+ * @return null|\OCP\IImage null if no preview was generated
+ * @since 17.0.0
+ */
+ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage;
+}
diff --git a/lib/public/Preview/IVersionedPreviewFile.php b/lib/public/Preview/IVersionedPreviewFile.php
new file mode 100644
index 00000000000..9266b1ac067
--- /dev/null
+++ b/lib/public/Preview/IVersionedPreviewFile.php
@@ -0,0 +1,25 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCP\Preview;
+
+/**
+ * Marks files that should keep multiple preview "versions" for the same file id
+ *
+ * Examples of this are files where the storage backend provides versioning, for those
+ * files, we dont have fileids for the different versions but still need to be able to generate
+ * previews for all versions
+ *
+ * @since 17.0.0
+ */
+interface IVersionedPreviewFile {
+ /**
+ * @return string
+ * @since 17.0.0
+ */
+ public function getPreviewVersion(): string;
+}